Here is how I find hard links located in /tmp
:
$ for file in /tmp/*; do if [ "$(stat -c %h -- "$file")" -gt 1 ]; then ls "$file" -l ; fi; done
total 0
srwxrwxr-x 1 t t 0 Mar 20 23:01 debconf.socket
total 0
srwxrwxr-x 1 t t 0 Mar 20 22:58 debconf.socket
total 0
srwxrwxr-x 1 t t 0 Mar 20 23:00 debconf.socket
total 0
-rw-rw-r-- 2 t t 39675802 Mar 23 01:06 /tmp/dd
total 0
lrwxrwxrwx 1 t t 5 Mar 21 12:52 d1 -> ../d1
total 676
-rw------- 1 t t 688899 Mar 22 21:46 image.png
total 0
total 352
-rw-r--r-- 1 t t 345008 Jun 2 2008 iwlwifi-5000-1.ucode
-rw-r--r-- 1 t t 2114 Jun 4 2008 LICENSE.iwlwifi-5000-ucode
-rw-r--r-- 1 t t 5099 Jun 4 2008 README.iwlwifi-5000-ucode
total 360
-rw-r--r-- 1 t t 353240 Apr 23 2009 iwlwifi-5000-2.ucode
-rw-r--r-- 1 t t 2114 May 19 2009 LICENSE.iwlwifi-5000-ucode
-rw-r--r-- 1 t t 5097 May 19 2009 README.iwlwifi-5000-ucode
total 348
-rw-r--r-- 1 t t 340688 Apr 20 2011 iwlwifi-5000-5.ucode
-rw-r--r-- 1 t t 2046 Dec 2 2010 LICENSE.iwlwifi-5000-ucode
-rw-r--r-- 1 t t 4922 Dec 2 2010 README.iwlwifi-5000-ucode
total 4
-rw-rw-r-- 1 t t 50 Mar 22 23:23 xauth-1000-_0
total 0
srw------- 1 t t 0 Mar 22 23:23 kdeinit4__0
srwxrwxr-x 1 t t 0 Mar 22 23:23 klauncherhX1003.slave-socket
total 0
total 4
-rw-rw-r-- 1 t t 402 Mar 13 07:39 note~
total 8596
-rw-r--r-- 1 t t 283 Feb 8 2106 content.xml
Most of detected files are not hardlinks, as there is only 1
reference to them. I wonder why I get these false positives? How can I find the hard links?
ls -ld "$file"
, both for adding thed
option (which, IMHO, you should always use unless you specifically want to list a directory) and also for the order. I am astonished thatls "$file" -l
works, and I strongly suspect that it's not as portable as the traditional "[OPTION]... [FILE]..." order. – Scott - Слава Україні Mar 23 '15 at 19:32ls . -l
andrm mydir -r
? – Tim Mar 24 '15 at 17:07POSIXLY_CORRECT=1 ls . -l
will sayls: cannot access -l: No such file or directory
and then list the current directory (in short form). I remember, before POSIX, that this is the way it was, always, period. … (Cont’d) – Scott - Слава Україні Mar 24 '15 at 19:34ls . -l
, you will have to re-learn how to type simple commands if you ever land on a POSIX-compatible system. … … … … And, yes,rm
seems to be a problem area. Historically,rm foo -r
andrm ./-r
were the two ways to delete a file called-r
— this is before--
was defined. … (Cont’d) – Scott - Слава Україні Mar 24 '15 at 19:35rm foo -r
out of habit. But I’m struggling to see how this would actually be a problem, though. I guess the biggest risk is if the user saysrm foo.d -r
, wherefoo.d
is a directory (especially if it has stuff in it). The user might think, “This will skip overfoo.d
, becauserm
doesn’t remove directories, and then it will remove-r
.” Of course, it’s pretty unwise to sayrm foo.d …
iffoo.d
exists and you don’t want it deleted. – Scott - Слава Україні Mar 24 '15 at 19:37rm foo -r
as an answer. – Scott - Слава Україні Mar 24 '15 at 19:41