by gavinhoward · 5y ago · 0 comments
First, we forget that filesystems are not hierarchies, they are graphs, whether DAG's or not. [1]
Second, and this follows from the first, both tags and hierarchy are possible with filesystems as they currently are.
Here's how you do it:
1. Organize your files in the hierarchy you want them in.
2. Create a directory in a well-known place called `tags/` or whatever you want.
3. For every tag `<name>`, create a directory `tags/<name>/`
4. Hard-link all files you want to tag under each tag directory that apply.
5. For extra credit, create a soft link pointing to the same file, but with a well-known name.
This allows you to use the standard filesystem tools to get all files under a specific tag. For example,
find tags/<name> -type f
(The find on my machine does not follow symbolic links and does not print them if you use the above command.)If you want to find where the file is actually under the hierarchy, use
find -L tags/ -xtype l
Having both hard and soft links means that 1) you cannot lose the actual file if it's moved in the hierarchy (the hard link will always refer to it), and 2) you can either find the file in the hierarchy from the tag or you know that the file has been moved in the hierarchy.Of course, I'm no filesystem expert, so I probably got a few things wrong. I welcome smarter people to tell me how I am wrong.
[1]: https://lobste.rs/s/ydno8w/tree_structure_file_systems#c_njg...
> 3. For every tag `<name>`, create a directory `tags/<name>/`
> 4. Hard-link all files you want to tag under each tag directory that apply.
Does this only give you one level of tags? (i.e you can't combine tags when exploring)
My first crack at it is this:
find -L tags/tag1 tags/tag2 -xtype l | sort | uniq -d
I don't know if that would work (on mobile; can't test), but from reading the man pages, it seems like it would do the trick. find -L tags/tag1 tags/tag2 -xtype l | xargs readlink -f | sort | uniq -dArticle roach motel is more like it. Though the roaches can escape via bitrot, and often do.
For a tl;dr, you can use the following to find files that have more than one tag:
find -L tags/tag1 tags/tag2 -xtype l | sort | uniq -d
The lesson here is that being able to use command-line tools makes up for perceived limitations of the filesystem model.Edit: After testing, I found the following works great:
find -L tags/tag1 tags/tag2 -xtype l | xargs readlink -f | sort | uniq -d