I need a terminal command to delete all images (*.jpg, *.png, *.gif, *.JPG, *.PNG, *.GIF) stored in myfolder and its subfolders, preserving the folders structure. I do not need to move them to trash folder.

I guess that some regular expressions are needed, but this overcomes my skills.

1 Answer 1


To just list them (for review/verification):

find MYFOLDER -type f \( -iname '*.jpg' -o -iname '*.png' -o -iname '*.gif' \) -ls

To move them to the Trash:

find MYFOLDER -type f \( -iname '*.jpg' -o -iname '*.png' -o -iname '*.gif' \) -exec mv '{}' ~/.Trash/ \;

To delete them directly (no way to get them back unless you have a backup):

find MYFOLDER -type f \( -iname '*.jpg' -o -iname '*.png' -o -iname '*.gif' \) -delete
  • 1
    There's also -delete as on option
    – mcdado
    Commented Dec 5, 2014 at 0:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .