linux – How can I find all hardlinked files on a filesystem? – Super User
Posted by jpluimers on 2021/08/25
[WayBack] linux – How can I find all hardlinked files on a filesystem? – Super User
use the following line (for sure you have to replace
/PATH/FOR/SEARCH/with whatever you want to search):find /PATH/FOR/SEARCH/ -xdev -printf '%i\t%n\t%p\n' | fgrep -f <(find . -xdev -printf '%i\n' | sort -n | uniq -d) | sort -nthis scans the filesystem only once, shows inode, number of hardlinks and path of files with more than one hardlink and sorts them according to the inode.
if you are annoyed by error messages for folders you aren’t allowed to read, you can expand the line to this:
find /PATH/FOR/SEARCH/ -xdev -printf '%i\t%n\t%p\n' 2> /dev/null | fgrep -f <(find . -xdev -printf '%i\n' 2> /dev/null | sort -n | uniq -d) | sort -n
It uses these commands:
–jeroen






jpluimers said
Twitter thread:
https://twitter.com/isotopp/status/1430397415501225986
Die Frage macht keinen Sinn.
Alle Files sind hardlinked. Ihr Link Count ist 1 oder höher.
Unix hat kein delete, aber unlink. Es entfernt einen der Namen einer Datei.
Dateien mit Link Count 0 und Use Count 0 werden vom OS freigegeben.
In traditionellem Unix listet ncheck die Namen zu Files auf, gegeben maj/min/inode. Das ist langsam, genau wie der find da.
In Linux ist das Dateisystem spezifisch und in debugfs als subcommand für ext2 bis 4 enthalten.
Jedes directory hat zwei Namen, den Namen und .
Jedes directory hat einen weiteren Namen für jedes Subdirectory, nämlich ..
Link Count minus 2 ist die Anzahl der Subdirectories eines Verzeichnis. GNU find benutzt das um manche suchen zu beschleunigen.
Darum gibt es den mkdir Systemaufruf, eine BSD Erweiterung.
Version 7 hat Verzeichnisse mit mknod angelegt und dann weitere Namen erzeugt. Das war nicht atomar, und man konnte sich da herein schmuggeln und so das Dateisystem zerstören. Mkdir/rmdir fixen das.