硬链接到`/`?

硬链接到`/`?

/Ubuntu 上有 24 个指向我的硬链接:

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

我想知道它们是什么。

/./..两个硬链接吗/

$ 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

下有 27 个文件/,并且 /有 4 个符号链接和 23 个子目录,每个子目录都包含一个硬链接/

$ 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

那么应该有 23+2=25 个硬链接到/.但为什么是24个呢?

谢谢。

答案1

包括目录在内,共有 28 个文件。

ls / | wc -l包括“total”行,但不包括...目录,因此 27 变为 28。

减去initrd.imginitrd.img.oldvmlinuzvmlinuz.old,因为它们不是目录链接(它们是常规文件或符号链接),得到 24。

相关内容