How to Use Mac Finder Tags in Terminal

How to Use Mac Finder Tags in Terminal

Wish you could wield the organizational magic of Finder tags right from a Terminal prompt? Find out here how to use Mac Finder tags in Terminal to add, remove or reset tags for files and folders flexibly and list files by tag to boot.

First, Guided by the Light

It is the infamous blue light — the same pesky hue blamed for keeping people awake at night — that helps guide birds to their destinations by day.

In migratory birds’ eyes, pairs of short-lived radicals form and decay in rapid succession under blue light. Because their spin is swayed by magnetism, birds might thus “see” the Earth’s magnetic field and fly along faint, guiding patterns.

Now, basking in the blue light of your computer’s monitor, wish you could be guided to “see” Finder tags for files and folders in Terminal?

How to Use Mac Finder Tags in Terminal

Using the Third-Party Application “Tag”

Time needed: 5 minutes

To get easy access to Mac Finder tags on the Terminal command line using the “tag” application:

  1. Install tag.

    Here’s how: You can install tag most conveniently using either Homebrew or MacPorts; you can also compile the application from the source code with Xcode.

  2. Use tag to examine a file’s tags.

    Here’s how: Use tag <filename> to see the tags currently applied to a file.
    Exampletag "First, Guided by the Light.md" will list the tags assigned to the Markdown document.
    Shortcuttag alone will list all visible files in the current directory with all their tags.
    Checking the tags for a file with tag in macOS Terminal

  3. Apply tags with tag in Terminal.

    Here’s how: Use tag -a <tag,"another tag",tag3> <files and folders> to apple one or more tags to one or more files.
    New tag: If the tag does not mach one you have previously set up on your Mac, tag will create the tag (without a color assigned).
    Exampletag -a "La De Du",Reading * will apply both the La De Du and the Reading tag to all files in the current directory.
    Nota bene: There is no whitespace that separates multiple tags; they are separated only with a comma; files are separated by whitespace.
    Tagging files in macOS Terminal using tag

  4. Remove individual tags from files using tag.

    Here’s how: Use tag -r <tag,"another tag",tag3> <files and folders> to remove a list of tags from a list of files.
    Exampletag -r Reading "First, Guided by the Light.md" will remove the Reading tag from the Markdown document.
    Escapism: You can either surround file and tag names that include whitespace with quotation marks or precede each whitespace character with a backslash character.
    Removing a tag from a file in Mac Terminal using tag

  5. List all files for a tag using tag in Terminal.

    Here’s how: Use tag -f <tag or tags> to list all files on the system that have all of the listed tags assigned.
    Exampletag -f "La De Du",Reading will list all files and folders that have both the La De Du and the Reading tag.
    Just this folder: In the current folder, you can also use tag -m <tag or tags> to find matching files.
    Finding files by tag using tag in Mac Terminal

In Finder:
How to Tag Files and Folders on a Mac
How to View Tagged Files and Folders on a Mac

Examine Tags for a File Using “Xattr”

To use the xattr utility that comes with macOS for examining a file or folder’s tags:

  • Use xattr -l <files or folders> on the Terminal command line.
    Here’s what happens: This command will print all file attributes; you can find the Finder tags under com.apple.metadata:_kMDItemUserTags: in encoded form (with the tag name at the end)..
    Example: xattr -l First,\ Guided\ by\ the\ Light.md will list all attributes including tags for the Markdown file.
    Just tags: To see just tags, you can use tag -p com.apple.metadata:_kMDItemUserTags <files or folders>.
    Listing the Finder tags for a file using xattr in macOS Terminal

Find Files by Tag Using “Mdfind”

To employ the standard macOS mdfind Terminal application to list files by tag:

  • Use mdfind 'kMDItemUserTags == "<tag>"'.
    Example: mdfind 'kMDItemUserTags == "Reading"' will list all files with the tag Reading.
    Listing files by tag using mdfind in Mac Terminal

How to Use Mac Finder Tags in Terminal: FAQ

Can I strip all tags off of files with tag?

Yes.

To quickly reset tags for a file using tag:

  • Use tag -s * <file> to remove all tags from the specified files.
    Why this works: The -s command sets a file’s tags to the list given, and * specifies no tags in this case (it means all tags with other commands, though).
    Example: tag -s * * will strip all files in the current directory off all tags.

Can I have tag work recursively through directories?

Yes.

Except for the finding command -f, you can add the switch -R to have tag go through directories recursively.
Example:

Can tag auto-complete tag names for me?

No.

You will have to enter or copy tag names manually; tag cannot auto-complete tag names.

(Tested with macOS Tahoe 26.0 and tag 0.10..0; first published October 2025)

Home » Mac Tips and Resources » How to Use Mac Finder Tags in Terminal