User Tools

Site Tools


tips:linux:findln

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

tips:linux:findln [2009/06/08 15:32] (current)
erik created
Line 1: Line 1:
 +====== How to identify and find Hardlinks? ======
  
 +<​code>​
 +> ls -l
 +total 4
 +-rw-r-r- ​   1 erik     ​erik ​           1 Feb 16 02:07 test
 +</​code>​
 +
 +<​code>​
 +> 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
 +</​code>​
 +
 +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:
 +
 +<​code>​
 +> 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
 +</​code>​
 +
 +''​Note:''​ Use: ''​ls -i''​ to also list directories.
 +
 +To find all hardlink to the same inode:
 +
 +<​code>​
 +> find / -xdev -inum 18587
 +/​home/​erik/​test/​test
 +/​home/​erik/​test/​test2
 +</​code>​
 +
 +''​Note:''​ Hardlinks have to be located on the same file system, use ''​df .''​ to determine the current filesystem.
tips/linux/findln.txt · Last modified: 2009/06/08 15:32 by erik