1

Sometimes I want my filesystem to be more like a database, where the location of a file is treated more like a taxonomy system allowing the file to have multiple locations the way a blog post can have multiple tags.

I know symlinks can be used to make files accessible from other locations, so this is the obvious work around if what I'm describing doesn't exist, but maybe(?) it does...

Is there a filesystem that allows files/directories to exist in multiple locations?

alec
  • 1,708
  • 7
    Isn't this exactly what hard links are? – pLumo Nov 22 '21 at 14:44
  • 1
    @pLumo: hard links doesn't work on directories. – Giacomo Catenazzi Nov 22 '21 at 15:53
  • 2
    Not a file system, but it is common (e.g. on docker) to bind mount directories in different places (technically the programs see them as different mounts, so different filesystems). – Giacomo Catenazzi Nov 22 '21 at 15:56
  • Like John said in the answer, hardlinks get you real close. But if a file could have multiple locations in a way that a filesystem was designed for, I'd think the files would be more aware of their locations. As this solution of hardlinks requires doing find /mount/point ... and wait a couple minutes for the command to complete, I think this is (perhaps among others) reason for John to say "no". – alec Nov 22 '21 at 17:12
  • @GiacomoCatenazzi thanks for pointing that out! I only tested it on files and was quite pleased. I'm disappointed to realize it doesn't work on directories as that would have been real nice. – alec Nov 22 '21 at 17:15
  • @alec: I think it is not done because it is difficult to track them. (you can create a loop, and delete the link to root, and you get unusable disk space. And hard links works only inside one file system. For sure I would use them if they were available (and I would pay a performance price on deleting hard links). – Giacomo Catenazzi Nov 23 '21 at 09:23
  • 1
    On Linux, you can use bind mounts to let the same directory appear in different places. It works on any filesystem, across filesystems and with both files and directories. But your talking about "tags" and "taxonomy" suggests that this is either an XY-problem or simply idle philosophizing. Using the Unix filesystem "more like a database" is about as appropriate as using bash like a programming language. –  Nov 24 '21 at 03:16

1 Answers1

7

If I'm interpreting your question correctly, the short answer is "no", but with a large caveat. You can create hard links, which will give you the same effect as symlinks with an important difference. If you start with file A in location 1, then you link file B in location 2 to file A, they appear identical. With a symlink, if you then delete file A, file B is worthless and is a dangling pointer. With a hard link, file B is intact and contains the expected contents. It's important to note that while symlinks can cross filesystem boundaries, hard links cannot. You use the ln command to create hard links similar to the way you use it to create symlinks.

While hard links make it appear that the file actually exists in two locations simultaneously, it actually exists only in one place on-disk and simply has filesystem inodes in multiple locations pointing to that same location. It's very much a splitting of technical hairs as to why the short answer is "no" and yet the "workaround" gives you pretty much exactly what I believe you're asking for.

John
  • 17,011
  • Is there a way to see all of a files locations(or pseudo-locations)? Does that require getting an inode id or something? – alec Nov 22 '21 at 14:59
  • 3
    @alec See https://unix.stackexchange.com/q/73538/315749 – fra-san Nov 22 '21 at 15:04
  • 3
    Some filesystems such as btrfs also allow you do make "reflink copies" of a file. So the contents is stored only once like for hardlinks but modifying one leaves the other ones alone. – Stéphane Chazelas Nov 22 '21 at 15:06
  • @alec if you name your files consistently, such as where the basename for a given "blog post" is always the same, and only the directory name changes (to represent the "tags" you speak of in the OP), then tools like locate become useful, or a simple find /mount/point -name filename.dat – Jim L. Nov 22 '21 at 18:45