ln /a/A /b/B
I would like to see at the folder
a where the file A points to by
You can find inode number for your file with
shows references count (number of hardlinks to particular inode) after you found inode number, you can search for all files with same inode:
will show filenames for inode NUM in current dir (.)
There isn't really a well-defined answer to your question. Unlike symlinks, hardlinks are indistinguishable from the original file. Filenames in directories are just references to an inode (which contains the file contents and file attributes). Creating a hard link creates another reference to the same inode. These references are unidirectional (in typical filesystems, at least) -- the inode only keeps a reference count.
This means that the only way to find the other references to a given inode is to exhaustively search over the file system checking which files refer to the inode in question. You can use 'test A -ef B' from the shell to perform this check.
UNIX has hard links and symbolic links (made with
Hard links have been around since the earliest days of UNIX (that I can remember anyway, and that's going back quite a while). They are two directory entries that reference the exact same underlying data. The data in a file is specified by its
Since inodes are unique only for a given filesystem, there's a limitation that hard links must be on the same filesystem (unlike symbolic links). Note that, unlike symbolic links, there is no privileged file - they are all equal. The data area will only be released when all the files using that inode are deleted (and all processes close it as well, but that's a different issue).
You can use the
Here's a script which does exactly that. You invoke it with:
and it will find all files on that filesystem which are hard links for that file:
Here's the script.
The first column will represent permissions. The second column will be the number of sub-items (for directories) or the number of paths to the same data (hard links, including the original file) to the file. Eg:
Based on the
This is somewhat of a comment to Torocoro-Macho's own answer and script, but it obviously won't fit in the comment box.
Rewrote your script with more straightforward ways to find the info, and thus a lot less process invocations.
I tried to keep it as similar to yours as possible for easy comparison.
Comments on this script and yours