13

How can you set tags on files on Ubuntu?

I want to tag all kind of files:

  • Images
  • Audio
  • Text
  • Office
  • Directories

The only solution I found was MetaTracker.

But this projects seems to be dead.

How can I solve this desktop issue?

It would be mind blowing super great if you could sync these tags with a server like nextcloud.

  • 1
    tried tracker, but it seems very broken – Anona112 Sep 21 '17 at 9:11
  • 1
    What is wrong with this q+a: askubuntu.com/questions/827701/… ? – Rinzwind Sep 21 '17 at 11:52
  • 1
    @Rinzwind thank you for pointing to question 827701. The upper most solution there should work. But I ask myself why this scripting is needed. Why is there no ready to use application? The linux libraries are really great. It is not missing much, just some polishing and linux could compete with apple products. But it seams that linux freaks love details, they care for details, but the high level use case of average non-geek users .... nobody cares for this. It's sad. – guettli Sep 22 '17 at 5:40
  • 2
    In my own opinion, Linux already does compete with Apple products (and wins every time). I just don't think tagging is that big of a thing because nobody really asks for it seriously. – Kaz Wolfe Sep 26 '17 at 17:58
  • 2
    @KazWolfe yes, you are right nobody asks for it. I like this quote: “If I had asked people what they wanted, they would have said faster horses.” ― Henry Ford. What I want to say: If there would be a reliable tagging api available on all distributions a lot of code duplication could get removed. The same problem gets solved over and over again. Photo management applications do it, music players do it, ubuntu search (dash) does it ... – guettli Sep 27 '17 at 7:55
5
+50

The best way seems to be the tagging file system tagsistant.

From the homepage:

Tagsistant is a tag-based filesystem for Linux that turns directories into tags and search your files for you.

Mount Tagsistant

Just tell Tagsistant the name of the directory you want to use, for example myfiles/ in your home. This directory is now a special place with custom rules that help you manage your files.

$ tagsistant ~/myfiles
$

Create your tags

Think to directories under tags/ as white stickers you write something on top of. Create as many tags as you need, ready to mark your files.

$ mkdir ~/myfiles/tags/startrek
$ mkdir ~/myfiles/tags/starwars
$ mkdir ~/myfiles/tags/scifi

Tag your files

After creating a tag in tags/, it will be available in store/. Copy your files inside it: that's how you tag files. The @ marks the end of the tag list and it's required.

$ cp first_contact.avi ~/myfiles/store/startrek/@
$ cp the_return_of_the_jedi.avi ~/myfiles/store/starwars/@

Find your files by tags

Compose your search query by choosing as many tags you desire. You can even combine the results of more than one query by placing a +/ in between, like in startrek/+/starwars/ which merges the files tagged startrek with the files tagged starwars.

$ ls ~/myfiles/store/startrek/@
first_contact.avi
$ ls ~/myfiles/store/startrek/+/starwars/@
first_contact.avi
the_return_of_the_jedi.avi

Activate relations between tags

$ mkdir ~/myfiles/relations/scifi/includes/startrek
$ ls ~/myfiles/store/scifi/@
first_contact.avi                # 1 file...
$ mkdir ~/myfiles/relations/scifi/includes/starwars
$ ls ~/myfiles/store/scifi/@
first_contact.avi
the_return_of_the_jedi.avi       # 2 files!

Tagsistant understands several relations:

  • includes: If A includes B, any file tagged as B can be automatically found inside A.
  • excludes: If A excludes B, any file tagged as B can't be found inside A even if it's tagged as A.
  • is_equivalent: If A is equivalent to B, then all the files in A are available in B and vice versa.

And there's even more!

Tag entire directories

$ cp -R ~/Photos/London ~/myfiles/store/photos/@
$ ls -l ~/myfiles/store/photos/@/
London
$ ls -l ~/myfiles/store/photos/@/London/
-rw-------  1 tx0 tx0 2.3M Sep 28  2009 bridge.jpg
-rw-------  1 tx0 tx0 3.0M Aug 30  2011 trafalgar_square.jpg
[ ... more files here ... ]

With Tagsistant you can tag entire directories. The directory itself will be tagged, not the files inside, saving space in the tag db.

Use triple tags

$ ls ~/myfiles/store/document:/author/eq/Tx0/@ 
$ ls ~/myfiles/store/document:/title/inc/Strategic/@ 
$ ls ~/myfiles/store/pictures:/aperture/gt/5.6/@ 
$ ls ~/myfiles/store/time:/hour/lt/3/@

Triple tags are advanced tags formed by a namespace (terminated by a colon) which identifies the domain of interest of the tag, a key which qualifies the tag, an operator (eq for equality, gt for greater than, lt for less than and inc for includes), and finally a value which quantifies the tag.

This seems to me the most consistent and elegant approach for file tagging on Linux. It's around for more than 10 years, so it's a mature solution as well, without the risk of disappearing soon.

| improve this answer | |
4

A similar question was asked previously: Selecting files from different folders

Is it possible in nautilus to select a bunch of files from a folder, then go to a different folder and add some more files to the selection?

The accepted answer with 6 up-votes was "No, unfortunately it is not possible.".

Refusing to be dissuaded I wrote a bash script to tackle the problem.


Bafman Begins

In response to the question I developed bafman (Born Again File Manager) which was only somewhat successful because there was little interest in the answer.

There are 13 screens in the answer, so here is one of them to give you the idea:

bafman 12

Bafman Returns

The bash code was posted in a separate answer below the first but revisions made it too large to fit within the 30K limit so the answer was deleted. If someone is interested in the bash script I'd be happy to resurrect the project and post it in github.

| improve this answer | |
  • This question is about tagging files. This means the tags should survive a reboot. I think the solution in your answer does not fit to the question. – guettli Jun 27 '18 at 8:00
  • @guettli The tags survive reboots and are stored in .bafmanDirs and .bafmanFiles. – WinEunuuchs2Unix Jun 27 '18 at 9:59
  • I am sorry, I read too fast. You developed a tool called bafman. I am unsure if coding is the right thing here. Maybe an agreement and a simple spec would be needed. But who should agree? The gnome developers? – guettli Jun 27 '18 at 10:36
  • @guettli Our sister-site Software Engineering has people discussing changes to Gnome Nautilus. For example this question: softwareengineering.stackexchange.com/questions/149824/… You might want to sign up there and post your own idea from here? As far as tags moving when the file is moved the only way I can think of is to use an empty file attributes field such as "Birth Date" and mask it with the flags. That will make the birth date look funny when listed out though. Although inactive the birth date field will be used soon by newer apps. – WinEunuuchs2Unix Jul 1 '18 at 16:01
3

If the files you are looking to tag are hosted in Nextcloud for file sharing, then you can use the Nextcloud files automated tagging app along with manual tagging.

Automated tagging

The official description reads:

An app for Nextcloud that automatically assigns tags to newly uploaded files based on some conditions.

The tags can later be used to control retention, file access, automatic script execution and more.

enter image description here

It works for Nextcloud 12 and 13.

To define tags, administrators can create and manage a set of rule groups. Each rule group consists of one or more rules combined through operators. Rules can include criteria like file type, size, time and more. A request matches a group if all rules evaluate to true. On uploading a file all defined groups are evaluated and when matching, the given tags are assigned to the file.

Manual tagging

And here you can see how the manual tagging of files is available since Owncloud/Nextcloud 9.x using the file manager in the web view.

GOTCHA

If you wish to search the tags through the Ubuntu desktop file manager, then this might not work unless you use WebDAV to mount the network share and do something with the Nextcloud WebDAV API.

| improve this answer | |
  • Strange but true, I only found offical docs at nextcloud.com about automatic tagging, but not about manual tagging. Am I blind? – guettli Jul 16 '18 at 13:56
0

I needed to tag files too and decided that in the absence of a built-in way of doing it, I would implement my tags in the filenames of files. That way you have the full power of bash expressions to search for files with particular tags, there is no issue of cp and mv etc losing the tags, and the tags are visible in a gui file manager.

For example you could decide to add (tag1,tag2...)" to the end of each of the filenames.

Edit: this suited me well where my tags were more to indicate file membership of one or more of three groups. For a more general tag application an easier syntax to use (with bash etc) at the end of filenames would be something like "filename !tag1 !tag2".

| improve this answer | |
  • Yes, this is a working work-around. But it is a work-around. Not a solution, not a plan and not a goal. – guettli Jun 26 '18 at 12:42
  • Indeed it iS. One problem with it is that if you change the tags of a file, the filename changes, so if say a script references the file then that breaks unless you had the foresight to refer to the file in a way that allows any number of tags after the base filename. – B.Tanner Jun 26 '18 at 13:05
  • @B.Tanner You could avoid the renaming problem by using untagged filenames, and adding the tags by creating hardlinked tagged filenames. Scripts should use the untagged filenames to be independent of the tagging. – muclux Jul 2 '18 at 6:22
  • @muclux thank you, yes great idea. For me personally it's only a theoretical problem (I don't have any scripts that operate on the "tagged" files) but I have always had a slightly uneasy feeling about changing the name of the file. This might be a good way of keeping the tags separate from the actual files. Will have to have a think about backup implications... – B.Tanner Jul 2 '18 at 14:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.