Friday, May 7, 2010

digging hard links

A couple of tips about hardlinks: to find all hard links in a specific namespace use something like this:

$ find -type f -links +1

this because hard links have, by definition, more than one link pointing to them, as you can see with ls or stat on one of them.

Another useful tip: to know about any hard link which is related to a specified file use something like:
$ find /home -xdev -samefile foo
this will print out all files which are hardlinked to foo. Remember that hard links have the same inode number which can be seen with
$ ls -li foo

once you know the inode number, you can also search for hard links with something like

$ find /home -xdev -inum 7465209
Have fun!

No comments: