Operating System - HP-UX
1846187 Members
4058 Online
110254 Solutions
New Discussion

Re: script for finding hardlinks

 
devhariprasad
Advisor

script for finding hardlinks

Can anyone of you give me a script for finding the hardlinks present in a particular directory(including the sub-directories in that location).
3 REPLIES 3
spex
Honored Contributor

Re: script for finding hardlinks

Hi,

This is horribly inefficient...

# find /path/to/dir -type f -print | xargs -i find /path/to/dir -type f -linkedto {} -exec ls -1i {} \; | sort -k1 | uniq

PCS
James R. Ferguson
Acclaimed Contributor

Re: script for finding hardlinks

Hi:

# find /path -xdev -type f -links +1|xargs ls -l

...a good example is:

# find /sbin -xdev -type f -links +1|xargs ls -l

...see the manpages for 'find' for more information.

Regards!

...JRF...
Peter Godron
Honored Contributor

Re: script for finding hardlinks

Hi,
please see:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=87389
and
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=36428

Either way you have to loop through the filenames in your directory tree.
So my (bad) solution would be to do a find and redirect the filename list.
Then use the filname list as input into your solution (inode or linkedto):

find -print > /tmp/x.lis
while read record
do

done < /tmp/x.lis