Unix/Linux Go Back    



search for hardlinks based on filename via find command

UNIX for Dummies Questions & Answers




Kindly Note - This is a Single User Post by Forum Member mib Regarding:
search for hardlinks based on filename via find command.
Please Follow The Primary Link Above to View the Full Discussion.

   
Old Unix and Linux 03-25-2001   -   Original Discussion by hunternjb
mib's Unix or Linux Image
mib mib is offline
Registered User
 
Join Date: Jan 2001
Last Activity: 8 July 2003, 3:54 AM EDT
Location: Calicut
Posts: 228
Thanks: 0
Thanked 7 Times in 4 Posts
find &ltdir&gt ! -type d -links +1 -ls|sort -n

this will print all hardlinks in specified directory, sorted by files i-node.

the ! -type d is to avoid directories.
The -links +1 will find all files that have MORE than 1 link. Hardlinked files have a link count of at least two.
The -ls is used to view the inode number after find has found the file.
- The sort -n will sort the list by inode number showing you which files are hardlinked together.

This will only work if your search includes the directories that contain all of the hardlinked files.


here is anotherway

f=`ls -i $srch_arg |awk '{print $1}'`
find / -inum $f

this will search all system and print any files that is hardlinked with $srch_arg



[Edited by mib on 03-25-2001 at 06:05 AM]