Skip to content
Ashley Harvey edited this page Nov 8, 2020 · 13 revisions

Tagging

Copy tags from another file

To copy tag our picture artichoke.jpg with the same tags as avocado.jpg:

$ tmsu tag --from=avocado.jpg artichoke.jpg

Querying

Query for files and show all of the tags for each match

$ tmsu files photograph country | xargs tmsu tags
/home/fred/photos/DCSC-142.jpg: country=uk daytime good landscape photo manual-focus
...

List untagged files in the current directory

$ tmsu untagged

Include untagged files in a negative query

In a negative query, where you are looking for files that don't have a particular tag or tags, you may want to include untagged files:

$ tmsu files --path /animals not hairy && tmsu untagged /animals

Summarize tags by count

$ for tag in $(tmsu tags); do echo ${tag}: $(tmsu files ${tag} -c); done | sort -t: -k 2 -n -r | column

Filesystem Operations

TMSU does not make any changes to your files in the filesystem (other than to its own database). As such, TMSU does not include any functionality for moving or renaming files. To make these operations easier, TMSU now includes a set of scripts for performing these operations:

Delete a file

$ tmsu-fs-rm path/to/file

Alternatively this can be done manually:

$ rm path/to/file && tmsu untag --all path/to/file

Move or rename a file

$ tmsu-fs-mv path/to/file new/path

Or manually:

$ mv path/to/file new/path && tmsu repair --manual path/to/file new/path

Merge files

Sometimes you may wish to remove duplicates of a file, e.g. as identified by tmsu dupes. To combine multiple files into one, preserving all of the taggings:

$ tmsu-fs-merge path/to/file1 path/to/keep

This will delete all but the last file specified, applying the tags from each file deleted to the final file.

To do this manually:

$ tmsu tag --from=path/to/file1 path/to/keep && rm /path/to/file1 && tmsu untag --all /path/to/file1

External Integration

Note Taking with Markdown

The versatility of TMSU means it isn't very difficult to extract tags from text files (e.g. Markdown) and feed them into TMSU, for example the following could be used to extract #tags from markdown files in the current directory and assign tags to them:

rg --pcre2 '(?<=\s#)[a-zA-Z]+(?=\s)' -t markdown -o \
        | sed s+:+\ + | sed s/^/tmsu\ tag\ / | bash

Other users have also implemented strategies for extracting YAML tags see for example this repository