Setup
The following sequence of commands is setup for my question.
root@cd330f76096d:/# cd
root@cd330f76096d:~# ls
root@cd330f76096d:~# mkdir -p my_dir/my_subdir
root@cd330f76096d:~# ls -hAil
total 12K
6175969 -rw-r--r-- 1 root root 3.1K Oct 15 2021 .bashrc
6175970 -rw-r--r-- 1 root root 161 Jul 9 2019 .profile
7382820 drwxr-xr-x 3 root root 4.0K Sep 6 19:34 my_dir
Context
Notice that my_dir
has three hard links, as per the output. Presumably they are:
./my_dir
my_dir/.
my_dir/my_subdir/..
However. . .
root@cd330f76096d:~# find . -xdev -inum 7382820
./my_dir
And that's it. Only one line.
Questions
What am I missing and/or how does ls -l
work?
I'm half expecting that the reason why I can't locate any more files with find
is that they refer to .
and ..
in which case I ask how exactly does ls -l
work with references to the source code.
Pre setup
The example above was created in a docker container, which for convenience I'm sharing below:
$ docker pull ubuntu:jammy
jammy: Pulling from library/ubuntu
Digest: sha256:aabed3296a3d45cede1dc866a24476c4d7e093aa806263c27ddaadbdce3c1054
Status: Downloaded newer image for ubuntu:jammy
docker.io/library/ubuntu:jammy
$ docker run -it ubuntu:jammy bash
ls
finds the link count? It doesn't "find the hard links" as in printing their paths like it does for symlinks (because that's not how "hard links" work). It just gets the count from thestat
system call. It's a reference-count for the inode so the kernel (or fsck) can know when to free the inode. – Peter Cordes Sep 07 '23 at 09:50