How to hard link a symlink?
I'm looking for a way to create a hard link to a symbolic link in OS X 10.8 aka Mountain Lion.
Here's a brief illustration (inode numbers shortened for easier digestion):
$ echo "Hello" > file $ ln file hardlink $ ln -s file symlink $ ln -s nofile dangling-symlink $ ln symlink redirected-hardlink $ ln dangling-symlink symlink-hardlink ln: dangling-symlink: No such file or directory $ ls -liog total 40 458 lrwxr-xr-x 1 6 8 Jan 00:54 dangling-symlink -> nofile 433 -rw-r--r-- 3 6 8 Jan 00:53 file 433 -rw-r--r-- 3 6 8 Jan 00:53 hardlink 433 -rw-r--r-- 3 6 8 Jan 00:53 redirected-hardlink 456 lrwxr-xr-x 1 4 8 Jan 00:53 symlink -> file
So the inode ids for "file" and "hardlink" are the same, as one would expect.
The inode id for "redirected-hardlink" is the same as those two, meaning the hard link has dereferenced "symlink", rather than linking to it directly.
Since "dangling-symlink" can't be dereferenced, my attempt to create a hard link for it fails.
Just as well, as that's not what I want anyway—what I do want is a hard link to the actual symlink, i.e. for "redirected-hardlink" to point to inode 456, not 433. And for that last command to not fail, but instead produce a hard link with node id 458
I know this is possible in Linux and FreeBSD (the former by default, the latter via `ln -P`), but so far have failed to find a way to achieve the same in OS X.
Any suggestions?
I need something that works without installing additional software—code that can be made to run on a standard installation plus Xcode is fine.
Many thanks in advance for any pointers!
Message was edited by: Ronald Jore Fixed typos.
OS X Mountain Lion (10.8.5)