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?

  • you could modify it to use the find command rather than a for loop if your intent is to process all .jpg files. – Elder Geek Sep 12 '16 at 15:28
  • it is, but I have no idea how I'd do that? – Dave Sep 12 '16 at 15:39
  • See: stackoverflow.com/questions/8509226/… Vivek Sethi answer appears to have the clues you seek. – Elder Geek Sep 12 '16 at 15:49

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.