1

I'm well aware of the difference between symbolic and hard links. I'm also aware of the dangers of creating hard links to directories.

Nevertheless, I'm insisting on creating a hard link to a directory and all of its subdirectories (on the same partition).

However, the following does not work:

root@fab-ux:/home/fab-user/Public
# ln --directory ../Documents/CV/ CV
ln: failed to create hard link ā€˜CV’ => ā€˜../Documents/CV/’: Operation not permitted

Is there a kernel/File System (Running on EXT4) parameter that will allow me to accomplish this foolishness?

Yes, I can mount bind, can hard link individual files through a cron job, ... But the point is that I want both the convenience of physically only one directory and all its files and the convenience of only uploading certain hard-linked directories in my Public directory to the cloud and the cloud software detects symbolic links and doesn't support them and most important of all: I'm running Ubuntu! Not OSX nor Windows: I want the system to do what I want!

Fabby
  • 35,017

2 Answers2

4

As long as you stay on a current kernel (it is a feature by the kernel rather then one of the filesystem) there is nearly no way around this limitations.

Limitations of hard links

To prevent loops in the filesystem, and to keep the interpretation of .. (parent directory) consistent, many modern operating systems do not allow hard links to directories. UNIX System V allowed them, but only the superuser had permission to make such links.

The Open Group Base Specifications Issue 7 (excerpt)

...Linking to a directory is restricted to the superuser in most historical implementations because this capability may produce loops in the file hierarchy or otherwise corrupt the file system. This volume of POSIX.1-2008 continues that philosophy by prohibiting link() and unlink() from doing this. Other functions could do it if the implementor designed such an extension...


Because there is no longer a system call like link() which don't checks the oldpath being a regular file the only way out may be creating a similar function to linkat() doing it your desired way.

cmks
  • 1,914
1

You can not create hard links to directories in linux. I have heard that OSX allows this for time machine to use, but not linux. The closest you can do is cp -l, which will create a new tree of directories mirroring the original, but hard link all of the regular files.

psusi
  • 38,031