Linux Format 254 (Sampler)

Page 20

Tutorials TMSU

Tagging files made easy Tagging people on social media posts still foxes Shashank Sharma – but with TMSU, at least the files on his disk are properly tagged and organised. e covered the basic usage of TMSU in LXF253. Briefly, it’s a nifty little command-line utility which can be used to tag all the files on your disk, leading to easy organisation. This is especially useful if you’ve been running the same distribution such as a rolling-release or a LTS edition for some time, as the number of files on your system will grow exponentially the longer you run the same distribution. With TMSU, you can tag any file on your disk with a simple tmsu tag <filename> <tag> command. The command expects a filename and a space-separated list of tags that you want to assign to the specified file. See last issue (LXF253) for how to install the minimalist but robust utility, its usage as well as the basics of the TMSU database.

W

our expert Shashank Sharma is a trial lawyer in New Delhi and avid Arch user. He’s always on the hunt for budget-friendly geeky memorabilia.

Smart lookup As we discussed last issue, the tmsu files command is used to list all the files in the TMSU database. You can alternatively run the tmsu files <tag> command to only list files in the database which are identified with the

Repairing the database

specified tag. But if you want to narrow down the files even more than is possible with this basic usage, you can do so using the and , or and not operators. This is especially useful if you use the same tags for different types of files. For instance, you can use the todo tag for all your work files, in-progress blog posts, half-baked videos for your YouTube channel and so on. You can still separate the different files and identify the one you’re looking for using these operators: $ tmsu files todo LXF-articles-to-do-list WS-sumit-arora.docx $ tmsu files todo not lxf WS-sumit-arora.docx

As you can see from the output produced by the two commands, the second command removes the file LXF-articles-to-do-list because of the not operator used in the command. Similarly, the command tmsu files LXF will list all the files which match the specified tag LXF , while the command tmsu files LXF not year=2018 will only list files tagged LXF but not assigned the year=2018 value. Using the or operator is just as straightforward, and you can even combine operators to restrict results even more, to quickly narrow down the files you’re looking

As TMSU only creates a symbolic link to all the tagged files and directories, the database can easily get out of sync with the actual files on the disk if you were to move the files or rename them. This is because TMSU doesn’t watch the filesystem for changes. You can run the tmsu status command to determine whether the database is out of sync or not. When run without any additional command options, the status command will check each file in the database with the corresponding file on the disk. The filenames it produces as output are preceded with either T, M, ! or U symbols, identifying the respective files as either Tagged, Modified, Missing or Untagged. Renamed files, identified with the ! symbol, which still reside in the same directory can be fixed in the database by running the tmsu repair command. TMSU will then report the changes it made to the database to bring it back into sync: tmsu repair Documents/ /home/linuxlala/Documents/LXF-tutorial-vim.odt: updated path to /home/linuxlala/Documents/LXF-tutorial-vim-possible. odt

When not provided a path as an argument, tmsu repair will fix all the tagged files in all the nested directories within the parent directory.

58     LXF254 September 2019

TMSU uses a standard Sqlite3 database to store information. You can use sqlite3 to read the database, or even export the content.

www.linuxformat.com


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.