22
9
I need to find all hardlinked files on a given filesystem. E.g. get a list of files, each line contains linked pairs, or triplets, etc.
I understand more or less how to do it, one needs to create a dictionary keyed by inode for all files/directories on a filesystem, exclude "." and ".." links, and then indodes with more than one name are hardlinks... But I hope that maybe a ready-made solution exists, or someone already wrote such a script.
15You can avoid the need for awk by using find's "-links +n' syntax. e.g. to find all files with at least two links and print out the necessary info:
find / -type f -links +1 -printf '%i %n %p\n'
– mbafford – 2015-01-16T14:50:47.157how about piping through
sort
(+uniq
)? i was curious so gave it a go on my main computer (16GB i5-2500k with ssd). with 2187757 files (find / -xdev -type f | wc
) takes 12 real secs when returning 3820 files / 570 inodes (time sudo find / -xdev -type f -links +1 -printf "%i\n" | sort | uniq | wc
). you would need to include the%n %p
for the actual files as i took them out for counting inodes. – northern-bradley – 2018-10-24T09:45:36.8131Thanks, this is not exactly what I wanted, but close enough. I can add '%i' to print the inode numbers and then sort/group by it... – haimg – 2012-10-10T15:59:05.093