7
$ sudo su
# dd if=/dev/zero of=./myext.img bs=1024 count=100
.
.
.
# modprobe loop
# losetup --find --show myext.img
/dev/loop0
# mkfs -t myext /dev/loop0
.
.
.
# mkdir mnt
# mount /dev/loop0 ./mnt
# cd mnt
# ls -al
total 17
drwxr-xr-x  3 root root  1024 Jul 21 02:22 .
drwxr-xr-x  11 shisui shisui  4096 Jul 21 02:22 ..
drwx------  2 root root 12288 Jul 21 02:22 lost+found

(Cut out some of the output of some commands). My first question is, why isn't mnt showing up in the ls -al output? All I see is root. I cd'd into \mnt so I expected to see it in my ls -al output.

But then what is the third link?

Finally, are all the link numbers in this ls -al output hard links? Or does this link count also include symbolic links?

Shisui
  • 173

1 Answers1

27

You don’t see mnt in the ls -al output because you’re inside mnt; it is represented by .

There’s another hard link to ., lost+found/..; this explains the count of 3 links to the directory:

  1. . which points to the directory itself;
  2. .. which also points to the directory, because it’s the root directory in the file system (see Why does a new directory have a hard link count of 2 before anything is added to it?);
  3. lost+found/.., which points back to the root directory (again, in the file system, so mnt here).

The link counts shown by ls -l count hard links only; symlinks aren’t included.

Stephen Kitt
  • 434,908