0

There are 24 hardlinks to my / on Ubuntu:

$ ls -ld /
drwxr-xr-x 24 root root 4096 May  6 13:39 /

I want to know what they are.

Is it correct that /. and /.. are two hard links to /?

$ ls -a /
.   bin   cdrom  etc   initrd.img      lib    lost+found  mnt  proc  run   share  sys  usr  vmlinuz
..  boot  dev    home  initrd.img.old  lib64  media       opt  root  sbin  srv    tmp  var  vmlinuz.old

$ ls /..
bin   cdrom  etc   initrd.img      lib    lost+found  mnt  proc  run   share  sys  usr  vmlinuz
boot  dev    home  initrd.img.old  lib64  media       opt  root  sbin  srv    tmp  var  vmlinuz.old

There are 27 files under /, and / has 4 symlinks and 23 subdirectories each containing a hard link to /:

$ ls / -l |wc -l
27

$ ls -l /
total 108
drwxr-xr-x   2 root root  4096 Apr 16 08:10 bin
drwxr-xr-x   3 root root  4096 May  5 10:46 boot
drwxrwxr-x   2 root root  4096 Mar  8 22:10 cdrom
drwxr-xr-x  17 root root  4640 May  6 19:56 dev
drwxr-xr-x 148 root root 12288 May  6 18:31 etc
drwxr-xr-x   4 root root  4096 Mar  8 22:12 home
lrwxrwxrwx   1 root root    33 May  5 10:44 initrd.img -> boot/initrd.img-3.16.0-37-generic
lrwxrwxrwx   1 root root    33 Apr 30 12:19 initrd.img.old -> boot/initrd.img-3.16.0-36-generic
drwxr-xr-x  24 root root  4096 Mar  9 11:48 lib
drwxr-xr-x   2 root root  4096 Mar  8 22:23 lib64
drwx------   2 root root 16384 Mar  8 22:07 lost+found
drwxr-xr-x   3 root root  4096 Mar  8 22:53 media
drwxr-xr-x   2 root root  4096 Apr 10  2014 mnt
drwxr-xr-x   9 root root  4096 Apr 15 23:43 opt
dr-xr-xr-x 252 root root     0 May  4 07:30 proc
drwx------   8 root root  4096 Mar 15 22:46 root
drwxr-xr-x  27 root root   940 May  6 13:11 run
drwxr-xr-x   2 root root 12288 Apr 24 03:21 sbin
drwxr-xr-x   3 root root  4096 Apr 22 19:24 share
drwxr-xr-x   2 root root  4096 Feb 18 14:33 srv
dr-xr-xr-x  13 root root     0 May  6 22:12 sys
drwxrwxrwt  15 root root 12288 May  6 22:17 tmp
drwxr-xr-x  10 root root  4096 Apr 22 19:19 usr
drwxr-xr-x  13 root root  4096 Feb 18 14:41 var
lrwxrwxrwx   1 root root    30 May  5 10:44 vmlinuz -> boot/vmlinuz-3.16.0-37-generic
lrwxrwxrwx   1 root root    30 Apr 30 12:19 vmlinuz.old -> boot/vmlinuz-3.16.0-36-generic

Then there should be 23+2=25 hard links to /. But why there are 24?

Thanks.

1 Answer 1

3

There are 28 files, including directories.

ls / | wc -l includes the "total" line but not the . and .. directories, so your 27 becomes 28.

Subtract initrd.img, initrd.img.old, vmlinuz, and vmlinuz.old, since they aren't directory links (they're regular files or symlinks), making 24.

2
  • total 108 isn't a file. ls without the -a option doesn't include the . and .. hard links.
    – Mikel
    Commented May 7, 2015 at 2:52
  • My system, Mac OS X, has only 22 directories, but a hardlink count of 30.
    – Random832
    Commented May 7, 2015 at 4:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .