A
A
Adolf Milos2019-01-13 18:31:30
linux
Adolf Milos, 2019-01-13 18:31:30

How to count the number of regular files in a directory that have MORE THAN 1 hard link (Linux)?

Hello, please help with the following task:
I need to write a script that determines the number of ordinary files in the current directory that have more than one hard link. If there are more than 10 such files, then output the word "many", if less, then "few".
I know how to get the path of the current directory, I know how to use find to list all regular files in the current directory. But I don't understand how to count HARD LINKS! If this is done in the same find, then you need to write -links <number of links>. But I need MORE than 2 of them.
I would be grateful for any help (documentation, sites, ready-made code, approximately the same solved problems, etc.)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Victor Taran, 2019-01-13
@YAVAY

hard links have the same inode,
and therefore there will be more than one
inode matches in fact, you can even do this if there are more than 10 inode matches, then this will be 10 files
5c3b63782345b338441056.png

L
Lynn "Coffee Man", 2019-01-13
@Lynn

man find
Numeric arguments can be specified as
+n
for greater than n,

S
Saboteur, 2019-01-13
@saboteur_kiev

Search for files (-type f) with hardlinks greater than x (-links +1)
find . -links +1 -type f

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question