Take the 2-minute tour ×

How could I get the list of all linked files on my system or from a certain directory. I used to create links but they became unmanageable with time. I want the list of all such links from a directory. Can anyone help?

share|improve this question
I think this belongs to serverfault –  Gabriel Sosa Nov 27 '09 at 19:33
What is serverfault? –  DKSRathore Nov 27 '09 at 19:35
try here: serverfault.com –  Gabriel Sosa Nov 27 '09 at 19:38
not serverfault... there is nothing server or network related here... it is superuser.com –  Juliano Nov 27 '09 at 19:47

4 Answers 4

up vote 19 down vote accepted

Finding symlinks is easy:

% find . -type l

Finding hard links is tricky, because if a subdirectory of the directory in question also has subdirectories then those increase the hard link count. That's how subdirectories are linked to their parents in UNIX (it's the .. entry in each subdirectory).

If you only want to find linked files (and not directories), this will work:

% find . -type f \! -links 1

This works because a file that does have hard links will have a link count > 1, and unlinked file has a link count == 1, hence this command looks for all files whose link count <> 1

Alternatively, on newer versions of find you could use:

% find . -type f -links +1

This works for the same reason as above; however, newer versions of find can take +n or -n instead of just a number. This is equivalent to testing for greater than n or less than n, respectively.

share|improve this answer
Wao, this was such a small command. Thanks Alnitak –  DKSRathore Nov 27 '09 at 19:50
Er... can a file have <1 link? I mean, wouldn't that make it a fileless inode? –  naught101 Oct 8 at 4:49
@naught101 well, supplying -1 would indeed fail to find any files. –  Alnitak Oct 8 at 9:00

find / -xdev -samefile filename

share|improve this answer

@OP, If you have GNU find, you can find hard links using -printf "%n", e.g.

find /path -type f -printf "%f/%n/%i\n" | while IFS="/" read filename num_hlinks inum
 echo "Filename: $filename. Number of hard links: $num_hlinks, inode: $inum"
 # if 2 or more files have the same inode number, then they are hard links. 
 # you can therefore count how many $inum that are the same and determine those hard links, which 
 # you have to try doing yourself.
share|improve this answer

See e.g. here https://www.gnu.org/software/findutils/manual/html_node/find_html/Hard-Links.html or combine Alnitak and amber_linux answer into find -L /where/to/search -samefile /some/link/to/file to find all hard and soft links to a given file.

share|improve this answer
Thanks a lot! This was exactly what I was looking for - how to find which other files are in fact the same file as the one I'm looking at. –  cb2 Jul 30 at 16:54

Your Answer


