Tag files in linux

Tagging files on Ubuntu

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

@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.

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.

@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 .

4 Answers 4

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

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.

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.
Читайте также:  Linux удалить все внутри папки

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.

Источник

How to tag everything stored in a Linux filesystem?

How would I accomplish the following in Linux using the BTRFS filesystem? In Mac OS X El Capitan you can use tags to organize files. You can tag files and folders to make them easier to find. Tags work with all files and folders. You can add multiple tags to any file (or folder?). https://support.apple.com/kb/PH22180?locale=en_US Of course, the purpose of these tags is for finding / searching by tag. Mac OS X Finder includes support for tags. In Linux, it’s OK if I have to use command line tools to accomplish tagging and search by tags (and related functions).

Are you looking for 3rd party tools to accomplish this or are you only interested in a (possibly non-existent) native-to-the-filesystem solution?

Any solution is of interest. I just learned that KDE Baloo might do this, and that would be of interest to me.

3 Answers 3

A possibility might be to use extended attributes, see xattr(7) for an introduction.

(But I believe they are not widely used today; on Debian and related distributions you need to install the xattr package then use the xattr command)

As far as simple file tagging goes the fundamental question is where/how the tags are stored? If the file system doesn’t have native support for tagging of heterogeneous file types two common (though far from ideal) approaches you’ll find are filename embedding and sidecars. The former means that your tags are actually inserted into the filename, e.g. foo.txt becomes foo-[tag1,tag2].txt. The latter, sidecar, means the tags are stored in a file located in the same directory, or a common subdirectory, as the file to be tagged. For example foo.txt might be accompanied by .foo.txt.tags.

Neither of those sound too appealing do they? Embedding strikes me as plain ugly but at least you don’t have to worry about how to keep your tags with a file if you move or delete it as is the case with sidecars.

Читайте также:  Notebooks compatible with linux

But apparently these tradeoffs are acceptable to some people and there are some satisfied customers of offerings like.

I’ve heard some positive things about an open-source, cross-platform solution called TagSpaces. This uses the embedded approach by default but there is an Enterpri$e version with support for sidecars. The feature set is appealing and the UI looks nice as well as easy to use. There also look to be APIs if you want to integrate with other clients or create your own (e.g. CLI). And there’s something to be said about the cross-platform aspect if you like to keep your files on more than one platform.

For this and other similar solutions it all comes down to whether you can live with the. let’s face it. kinda hacky tag persistence details! 🙂

Edit: Here’s some info from someone who uses embedded tags: Adding tags to files (PDFs) and process from the command-line or script The rest of the thread may be of interest, too.

Источник

What’s a good solution for file-tagging in linux? [closed]

Questions seeking product, service, or learning material recommendations are off-topic because they become outdated quickly and attract opinion-based answers. Instead, describe your situation and the specific problem you’re trying to solve. Share your research. Here are a few suggestions on how to properly ask this type of question.

  • any file readable by the user can be tagged freely
  • a user can search for files matching one or several tags
  • files can be moved around without losing the previously associated tags
  • the system could be backed up easily
  • no dependencies on any desktop environment
  • if any gui is involved, there must be a cli fallback

I’ve been hoping for some basic filesystem & coreutils hackery to handle this, but I haven’ thought about this hard enough yet.
Meanwhile I’ll review beagle and metatracker, which have been mentionned here, and see how they perform.

Ok so beagle has huge gnome dependencies, and tracker is okish, but still has some dependencies I don’t like.

Been doing some more research, and the way to go could very well be extended file attributes.
That’s a native solution for most recent filesystems, but they aren’t very well supported yet (most coreutils destroys them by default, cp for example needs the -a flag to preserve them). Would like to hear some thoughts on using them while I try my hand at some hacks myself, eventhough this might warrant a new question.

Issues with extended file attributes: (i) In my experience, they are a nuisance when you want to backup. (ii) You can’t use them when you move between filesystems. Apart from that, they would be the Right Thing.

In PC-BSD Forums, with reference to the 2010 edition of this question: PC-BSD, extended attributes and tagging; OpenMeta and Apple’s approach

Читайте также:  Команда выключения сервера линукс

13 Answers 13

It’s not clear what kind of searching you want. If you want it to work anywhere in unix, rather that just your home directory, and you only want to do pathname-based searches, the following scheme is workable, with a little bit of shell hackery, and using the standard locatedb :

  1. Each directory that contains at least one tagged file needs a standard subdirectory, say .path-tags ;
  2. Each file in the directory $FILE with link $TAG (which should not contain the char _ ) has a link $TAG_$FILE -> ../$FILE

I leave the details of the locate-tag script to you; it should be a two- or three-liner, using only the locate command and shell hackery. (If you’re interested, I could write one).

Some of the KDE chaps talked about this sort of scheme for metadata, although I don’t recall the details.

It should also be possible to do more sophisticated, content-examining tests based on this scheme with a similar script wrapped around find .

Thoughts on updated requirements

  1. any file readable by the user can be tagged freely — Yes, should be no problem
  2. a user can search for files matching one or several tags — Likewise
  3. files can be moved around without losing the previously associated tags — The directories they inhabit can be freely moved about, but if the file is moved from the directory, we are in trouble. If the tags took the form $TAG_$INODE_$FILE and we have an efficient way to find which paths have a given inode, then we can do this, losing tags only if we move out of filesystems. Copying files might make some trouble, and this is clearly more complicated than my original suggestion.
  4. the system could be backed up easily — not essentially difficult.
  5. no dependencies on any desktop environment — none
  6. if any gui is involved, there must be a cli fallback — that’s where we live!

Postscript The «reverse-inode-lookup» file described by the link (2) you showed me in your answer to (1) can be used to give some additional infrastructure. We can run a service on the reverse lookup file, which checks that each inode given in the filename of a tag matches the inode of the file (if any) the tag points to. If there is no match, then the required surgery can be performed (does the inode still exists? where is it?), and the reverse lookup file being either mutated or regenerated, and the tag symlinks being updated.

I anticipate one tricky case: what if the tagged file is not where the tags say it should be, the reverse lookup file says it still exists, but the prodigal file is not where the lookup file says it is, the lookup file being out of date? There are a few ways to handle this case, none obviously ideal. Apart from this, this whole task seems to be the kind of thing Perl is well-suited to.

Источник

Оцените статью
Adblock
detector