M: A quick command line loop for Linux to add a tag “xyz” to an image
G: Here’s a quick bash one-liner
using exiftool to add a tag (keyword) xyz to
all images in the current directory:
for img in *.jpg; do exiftool -overwrite_original -Keywords+=xyz "$img"; done*.jpg can be replaced with *.png,
*.jpeg, etc., or * to target all files.-overwrite_original prevents backup files from being
created.-Keywords+=xyz adds xyz to the existing
keywords without removing others.If you want to process subdirectories too:
find . -iname '*.jpg' -exec exiftool -overwrite_original -Keywords+=xyz {} \;Let me know if you want to tag a different metadata field (like
Description, Title, etc.).
M: What about for multiple tags?
G: For multiple
tags, you can just repeat the -Keywords+= option
for each tag:
for img in *.jpg; do exiftool -overwrite_original -Keywords+=xyz -Keywords+=abc -Keywords+=123 "$img"; donefind . -iname '*.jpg' -exec exiftool -overwrite_original -Keywords+=xyz -Keywords+=abc -Keywords+=123 {} \;-Keywords+=tag appends that tag.-Keywords="tag1, tag2, tag3" would
replace all keywords, not append.-Keywords+='My Tag'If you want to batch-append the same set of tags to all files at once:
exiftool -overwrite_original -r -Keywords+=xyz -Keywords+=abc -Keywords+=123 .This will process all images recursively starting from the current directory.
Let me know if you want to target a metadata field other than
Keywords.
M: Is there another tag type besides keywords? And is there any way to add the tag without changing the last time the computer says it was modified?
G:
SubjectTitleDescription (or ImageDescription)CommentTagsListexiftool with -P to preserve the
filesystem timestamps.KeywordsHere are useful alternatives depending on what you want: | Field |
Purpose | Example exiftool flag |
|------------------|------------------------------------------|----------------------------------|
| Subject | Often used for topics or categories |
-Subject+=xyz | | Title | Short descriptive
title | -Title="My Image" | | Description |
Longer image description | -Description="Some text" | |
ImageDescription | EXIF-specific description |
-ImageDescription="Details" | | Comment |
General comment | -Comment="Note here" | |
TagsList | XMP tag list (can be more standardized) |
-TagsList+=xyz |
Keywords vs. Subject:
Some programs (like Lightroom) useKeywordsprimarily, while others (like Windows Explorer) displaySubjectmore prominently.
By default, exiftool changes the filesystem modification
timestamp.
To prevent that:
exiftool -P -overwrite_original -Keywords+=xyz filename.jpgfor img in *.jpg; do exiftool -P -overwrite_original -Keywords+=xyz -Keywords+=abc "$img"; done-P = Preserve filesystem modification date/time.-overwrite_original = Don’t create backup files.-Keywords+= = Append the tag without replacing existing
ones.-P will preserve "last
modified" and "last changed" timestamps on disk.Keywords and Subject can
improve cross-compatibility.Let me know if you want to write the same tags to multiple metadata fields simultaneously.