On 4/9/24 10:20 PM, Carl Edquist wrote:
On Tue, 9 Apr 2024, Tony Freeman wrote:
I seem to recall that some years ago ls -l would show the number of hard
links to a file.
Yes with "ls -l" it's the first number you see (after the permissions string). Or you
can use "stat -c %h filename" to just grab that number specifically.
Indeed, while ls(1) is good for interactive output and judging from the eyes,
stat(1) may be a better choice for script-like processing.
Yet another alternative: use 'find -printf' with the '%n' directive:
%n Number of hard links to file.
Here's a way to find the regular file with the most hardlinks (318!) on my '/'
filesystem:
$ find / -xdev -type f -printf '%n %p\0' \
| sort -z -k1,1n \
| tail -z -n1 \
| sed 's/^[0-9]* //' \
| xargs -0 ls -logdi
1311404 -rw-r--r-- 318 23 Mar 13 09:31
/usr/lib/locale/zu_ZA.utf8/LC_MEASUREMENT
Obviously, there are 317 other file names pointing to the same file / inode
in that file system.
Have a nice day,
Berny