Timeline for How to find all hard links to a given file?
Current License: CC BY-SA 4.0
11 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Aug 22, 2022 at 12:59 | comment | added | mistige | Expanding on John1024's answer, here's a script which lists all the files that have multiple hardlinks with a counter in first column, the inode-nr in the second, and other 'ls' output at the end, helping to determine the scope of the hardlinks [[[ find ./ -type f -exec find . -samefile {} -ls \; | sort -rn | uniq -c | sort -rn ]]] | |
| Nov 11, 2021 at 12:00 | comment | added | pgr | Thank you for the extra info, very useful. For me, this raises an additional question - how to find which files/dirs have links that I should care about (as opposed to default ones), and which are they exactly? Maybe answering those questions is too complex for a one-liner, and would require a script. | |
| Nov 10, 2021 at 22:25 | comment | added | John1024 | @pgr I just this documented online and updated the answer to include the information. Thanks for mentioning this! | |
| Nov 10, 2021 at 22:24 | history | edited | John1024 | CC BY-SA 4.0 |
added 815 characters in body
|
| Nov 10, 2021 at 22:11 | comment | added | John1024 |
@pgr As counted by ls -al, every directory has a minimum of two links: itself and .. In addition, if it has subdirectories, then every subdirectory has a file .. that is a hard link back to its parent directory. Thus, according to ls -al, a directory with two subdirectories has a total of four hard links. By contrast, find / -samefile does not include the . and .. directories in its count.
|
|
| Nov 9, 2021 at 18:55 | comment | added | pgr |
What could be a reason for the following behaviour? ls -al shows var/www/html/logs to have 4 links to it. I run find / -samefile /var/www/html/logs as user root and it shows me only one entry, not 4... what gives?
|
|
| Jan 30, 2018 at 17:01 | comment | added | reinierpost | Of course. You're listing entries in directories. You need read access to those directories in order to list them. | |
| Jan 16, 2018 at 6:55 | comment | added | Aaron Brick | The result of this query is incomplete for users lacking privileges on the directories that contain the hard links. | |
| May 7, 2015 at 3:25 | vote | accept | Tim | ||
| May 7, 2015 at 2:57 | history | edited | John1024 | CC BY-SA 3.0 |
added 331 characters in body
|
| May 7, 2015 at 2:52 | history | answered | John1024 | CC BY-SA 3.0 |