• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 294
  • Last Modified:

How to find the hard linked file?

How can I see whether a given file is hardlinked or not? like given a file how can I find how many files are sharing the same inode number? Thanks!
3 Solutions
Or, even better it seems...

find . -inum <inode_number>

From: http://en.wikipedia.org/wiki/Inode#Practical_considerations
If you do

ls -l filename

the number in the 2nd column indicates the number of hardlinks the file has.

To find all the files that are hardlinked to it, do

ls -i filename

The first number is the inode.  Then do

find . -inode <inode_number> -ls
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Note that inode numbers are unique within a file system so you may get a file with inode number <inode number> is each mounted filesystem. Tintin's method works if your current directory is that containing the file and if your "find" have the "-inode" parammeter. For example AIX "find" needs parameter "-inum".
Whoops, inode was a type, I meant inum.  To prevent find searching outside the filesystem, add the -xdev flag, eg:

find . -xdev -type f -inum <inode_number> -ls
beer9Author Commented:
Thank you :-)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now