> ls -l
total 4
-rw-r-r- 1 erik erik 1 Feb 16 02:07 test
> ln test test2
> ls -l
total 8
-rw-r-r- 2 erik erik 1 Feb 16 02:07 test
-rw-r-r- 2 erik erik 1 Feb 16 02:07 test2
Notice field 2 changed from 1 to 2 indicating that a hard link has been created. There are now 2 filenames pointing to the same data.
To list all hardlinked files in the current directory:
> find . ! -type d -links +1 -ls | sort -n
18587 4 -rw-r-r- 2 erik erik 1 Feb 16 02:07 ./test
18587 4 -rw-r-r- 2 erik erik 1 Feb 16 02:07 ./test2
Note
Use:
ls -ito also list directories.
To find all hardlink to the same inode:
> find / -xdev -inum 18587
/home/erik/test/test
/home/erik/test/test2
Note
Hardlinks have to be located on the same file system, use
df .to determine the current filesystem.