Reinventing file storage with semantic tagging
Date2name and Appendfilename
The Date2name tool [7] adds the date and timestamps at the beginning of the file name. The command:
date2name "foo bar.txt"
renames the file to 2019-09-26 foo bar.txt
.
date2name --withtime "foo bar.txt"
would give you 2019-09-26T14.45 foo bar.txt
.
One frequently recurring step when working with files is adding words from the actual file name. If you want to add a description to a photo named 2019-09-26T14.52.36.jpg
, use the Appendfilename [8] tool. The following call:
appendfilename --text="foo bar" 2019-09-26T14.52.36.jpg
renames the file to 2019-09-26T14.52.36 foo bar.jpg
. Without the --text
parameter, the tool waits for text input in interactive mode.
If you wrap the call in a script, as shown in Listing 2, Appendfilename can extend all selected files in a file browser after you enter and confirm the text in the window that appears.
Listing 2
Wrapping Appendfilename
/usr/bin/gnome-terminal \ --geometry=90x5+330+5 \ --hide-menubar \ -x appendfilename "${@}"
Filetags
Like Appendfilename, Filetags [9] adds text to the file name, but without you needing to worry about separators in front of the tags. Both the command in the first line of Listing 3, and the one in the second line result in foo -- bar baz.txt
as the file name. The command form in Line 3 converts back to foo.txt
.
Listing 3
Adding Tags
$ filetags --text "bar baz" "foo.txt" $ filetags --text "baz" "foo -- bar.txt" $ filetags --remove --text "baz bar" "foo -- bar baz.txt"
In interactive mode without the --text
parameter, you can remove existing tags by prepending a minus sign: -bar baz
removes the bar
tag and adds baz
.
The tool also suggests tags based on their use in other files in the same directory. These suggestions assign file tags with numbers starting at 1. You can reuse these abbreviations in your input. For example, interactively inputting 1 bar 42
tells the tool to add suggestions 1, 2, and 4 together with the bar
tag.
In addition, Filetags offers a tab completion option. To manage this, it is a good idea to create a .filetags
file in the current directory or a parent directory. The software searches recursively upwards; the first definition file found wins. This means you can have different definitions for different hierarchies.
The structure of this text file is very simple. Each line consists of one or more tags. If several of them are in one line, Filetags treat them as mutually exclusive. Based on the .filetags
file in Listing 4, if you add a tag of foo -- draft.txt
to a final
file, Filetags will automatically replace the draft
tag with final
instead of appending it.
Listing 4
.filetags File
presentations cheatsheets cliparts finance manuals templates draft final submitted
Guessing and Unpacking
The Guessfilename [10] tool, written in Python, helps to rename frequently used file names. Using pattern recognition in the file name and by parsing the contents where necessary, it determines variants for the file names. If your monthly pay slip is sent in the form of a PDF file such as Salary.pdf
, it recognizes the Salary
character string and the PDF file type by reference to a configured pattern and generates the new file name 2019-09-29 Pay slip September -- finance company.pdf
.
It is in the nature of things that you have to adapt Guessfilename to suit your own needs – it is practically just a template for customization. To customize the crucial derive_new_filename_from_old_filename()
function, you need basic Python programming skills.
To compensate for the overhead, you can look forward to many simplifications in daily file handling. I use Guessfilename not only for pay slips, but also for audio recordings, digital photos directly from the camera, screenshots, invoices, and other files – wherever programs do not let you configure the file name to suit a desired scheme.
The Guess-target-folder.sh
and Move2archive [11] tools take care of the next logical step: moving the files to the appropriate target folder. Both scripts in this form are usually only useful on Unix-style operating systems.
Guess-target-folder.sh
is a trivial, but again highly personalized, shell script. Listing 5 outlines the basic mechanism. Move2archive behaves in a very similar way, but it does not support pattern recognition. It simply moves the files to a folder structure, where the directory names consist of an archivepath
(like $HOME/archive/
) and the year.
Listing 5
Guess-target-folder.sh
# Guess-target-folder.sh # file="${1}" move_file() { file="${1}" targetdir="${2}" echo "* ${file}\n -> ${targetdir}" mv "${file}" "${targetdir}" } case "${file}" in 20*Columbo*mp4) move_file "${file}" "$HOME/tv/detectivestories/";; 20*Meter_reading\ Water*pdf) move_file "${file}" "$HOME/correspondence/wasser/";; *Salary*pdf) move_file "${file}" "$HOME/correspondence/company/";; *1234567*|*1.234.567*) move_file "${file}" "$HOME/correspondence/insurance/";; esac
The two Python scripts can be installed using Pip3 if required. The particularly annoying integration on Windows systems prompted the development of Integratethis [12], which supports easy integration into Windows Explorer. But there is no reason why it should not be taught how to integrate with Geeqie, Thunar and other interfaces. Appropriate pull requests on Github are welcome.
« Previous 1 2 3 Next »
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Canonical Bumps LTS Support to 12 years
If you're worried that your Ubuntu LTS release won't be supported long enough to last, Canonical has a surprise for you in the form of 12 years of security coverage.
-
Fedora 40 Beta Released Soon
With the official release of Fedora 40 coming in April, it's almost time to download the beta and see what's new.
-
New Pentesting Distribution to Compete with Kali Linux
SnoopGod is now available for your testing needs
-
Juno Computers Launches Another Linux Laptop
If you're looking for a powerhouse laptop that runs Ubuntu, the Juno Computers Neptune 17 v6 should be on your radar.
-
ZorinOS 17.1 Released, Includes Improved Windows App Support
If you need or desire to run Windows applications on Linux, there's one distribution intent on making that easier for you and its new release further improves that feature.
-
Linux Market Share Surpasses 4% for the First Time
Look out Windows and macOS, Linux is on the rise and has even topped ChromeOS to become the fourth most widely used OS around the globe.
-
KDE’s Plasma 6 Officially Available
KDE’s Plasma 6.0 "Megarelease" has happened, and it's brimming with new features, polish, and performance.
-
Latest Version of Tails Unleashed
Tails 6.0 is based on Debian 12 and includes GNOME 43.
-
KDE Announces New Slimbook V with Plenty of Power and KDE’s Plasma 6
If you're a fan of KDE Plasma, you'll be thrilled to hear they've announced a new Slimbook with an AMD CPU and the latest version of KDE Plasma desktop.
-
Monthly Sponsorship Includes Early Access to elementary OS 8
If you want to get a glimpse of what's in the pipeline for elementary OS 8, just set up a monthly sponsorship to help fund its continued existence.