The Computer Oracle

exiftool: delete exif data but preserve some specific tags

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Luau

--

Chapters
00:00 Exiftool: Delete Exif Data But Preserve Some Specific Tags
00:21 Accepted Answer Score 7
01:15 Answer 2 Score 2
02:19 Thank you

--

Full question
https://superuser.com/questions/450838/e...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#macos #commandline #unix #exif #exiftool

#avk47



ACCEPTED ANSWER

Score 7


You should always check the man pages if you are in trouble.

man exiftools

Which should read something like this:

--TAG

    Exclude specified tag from extracted information.  Same as the -x
    option.  May also be used following a -tagsFromFile option to
      exclude tags from being copied, or to exclude groups from being
    deleted when deleting all information (ie. "-all= --exif:all"
    deletes all but EXIF information).  But note that this will not
    exclude individual tags from a group delete.  Instead, individual
    tags may be recovered using the -tagsFromFile option (ie. "-all=
    -tagsfromfile @ -artist").  Wildcards are permitted as described
    above for -TAG.

Something like:

exiftool -overwrite_original -all= -tagsFromFile @ -title -caption -keywords /Users/andyl/photos/*.jpg

should work. Ensure that the tags really are named this way using exif /path/to/file.jpg.

What the command does? -all= deletes all the tags, -tagsFromFile @ takes the listed flags from the source file, in this case @ represents the current file, (you could of course substitute with a fixed file here like -tagsFromFile pic.jpg) and writes them to the destination.




ANSWER 2

Score 2


If you only want to delete certain tags from the original file (i.e. no transfer from tags between files, but from within the same file), you do not need the -tagsFromFile switch, but a < to tell to transfer them along the file.

Note: As of now (version 10.79) -common<common cannot set composite tags and therefore using -common to transfer tags will break things, e.g. tranferring Flash to Model. Therefore, my code is explicit and includes every tag that -common would normally include. Seems to be a good idea, anyway.

exiftool -All:All= \
         -DateTimeOriginal<DateTimeOriginal \
         -Model<Model \
         -LensModel<LensModel \
         -FocalLength<FocalLength \
         -ISO<ISO \
         -ExposureTime<ExposureTime -ShutterSpeedValue<ShutterSpeedValue -BulbDuration<BulbDuration \
         -ApertureValue<ApertureValue -FNumber<FNumber \
         -WhiteBalance<WhiteBalance \
         -Flash<Flash \
         test.jpg
  # Or, if you want to use `-TagsFromFile`:
exiftool -All:All= \
         -TagsFromFile test.jpg \
         -DateTimeOriginal \
         -Model \
         -LensModel \
         -FocalLength \
         -ISO \
         -ExposureTime -ShutterSpeedValue -BulbDuration \
         -ApertureValue -FNumber \
         -WhiteBalance \
         -Flash \
         test.jpg

Please also note that my code contradicts the exiftool application documentation, which includes samples that I simply could not get to work with this task at hand (and version 10.79).