for i in *.jpg; do echo "Processing $i"; exiftool -all= "$i"; done

I need to adapt this line of code which strips all exif info from images in a directory. I need it to;

  • not fail if the current directory is empty
  • be recursive to deal with sub-directories
  • cover *.gif *.jpeg *.png as well

Could anyone point me in the right direction?


2 Answers 2


There is no need to script this, ExifTool can do it by itself and it will be much faster than looping through items.
exiftool -r -all= -ext jpg -ext gif -ext png /path/to/top/directory/

-r recurse through subdirectories
-ext … limit processed files to specified extentions, remove these items to process all files that Exiftool can remove metadata for.


Since exiftool is awesome, then there's no need for it, but in principle you could do with find something like this...

First check that your search finds what you want (using -iname to make it search case insensitively since both .JPG and .jpg etc are common)

find . -iname '*.jpg' -or -iname '*.png' -or -iname '*.jpeg' -or -iname '*.gif' 

if will output a list of found files with paths starting here (including subdirectories)

then repeat adding the command to act on the files found at the end | xargs exiftool -all=

find . -iname '*.jpg' -or -iname '*.png' -or -iname '*.jpeg' -or -iname '*.gif' | xargs exiftool -all=

or safer if filenames have spaces, to use null as a delimiter instead of spaces:

find . -iname '*.jpg' -print0 -or -iname '*.png' -print0 -or -iname '*.jpeg' -print0 -or -iname '*.gif' -print0 | xargs --null exiftool -all=

If nothing matches (for example the directory is empty) then it does nothing

. is the current working directory. If you aren't there, replace find . with find /path/to/parent/directory

You must log in to answer this question.

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