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
-
Latest Cinnamon Desktop Releases with a Bold New Look
Just in time for the holidays, the developer of the Cinnamon desktop has shipped a new release to help spice up your eggnog with new features and a new look.
-
Armbian 24.11 Released with Expanded Hardware Support
If you've been waiting for Armbian to support OrangePi 5 Max and Radxa ROCK 5B+, the wait is over.
-
SUSE Renames Several Products for Better Name Recognition
SUSE has been a very powerful player in the European market, but it knows it must branch out to gain serious traction. Will a name change do the trick?
-
ESET Discovers New Linux Malware
WolfsBane is an all-in-one malware that has hit the Linux operating system and includes a dropper, a launcher, and a backdoor.
-
New Linux Kernel Patch Allows Forcing a CPU Mitigation
Even when CPU mitigations can consume precious CPU cycles, it might not be a bad idea to allow users to enable them, even if your machine isn't vulnerable.
-
Red Hat Enterprise Linux 9.5 Released
Notify your friends, loved ones, and colleagues that the latest version of RHEL is available with plenty of enhancements.
-
Linux Sees Massive Performance Increase from a Single Line of Code
With one line of code, Intel was able to increase the performance of the Linux kernel by 4,000 percent.
-
Fedora KDE Approved as an Official Spin
If you prefer the Plasma desktop environment and the Fedora distribution, you're in luck because there's now an official spin that is listed on the same level as the Fedora Workstation edition.
-
New Steam Client Ups the Ante for Linux
The latest release from Steam has some pretty cool tricks up its sleeve.
-
Gnome OS Transitioning Toward a General-Purpose Distro
If you're looking for the perfectly vanilla take on the Gnome desktop, Gnome OS might be for you.