bug-findutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: find inodes of a dir


From: Martin Schulte
Subject: Re: find inodes of a dir
Date: Sat, 15 Aug 2020 18:47:43 +0200

Hi Andrei!

> I’m trying to identify all hard links pointing to my root directory:
> $ sudo ls -lid /
> 2 drwxr-xr-x 23 root root 4096 Aug 11 20:58 /
> 
> The inode number is 2 and count of hard links is 23.
> 
> Then I run find:
> 
> $ sudo find / -xdev -inum 2 2>/dev/null | wc -l
> 15

I'm rather astonished that you find 15 and not only one...

First of all these results might depend on the type of underlying filesystem - 
I'm answering for a "classical" Unix filesystem, I'm using with ext4 here.

Keep in mind that there you can't "manually" create hard links to a directory, 
the only way to increase the link count of a directory is to create a 
subdirectory in it.

In the directory where you created a directory "dir" you have one link to the 
directory. Inside "dir", "." is the second link, and for each direct 
subdirectory of dir ".." is another.

$ ls -lid dir dir/. dir/sub1/.. dir/sub2/.. dir/sub3/..
13918312 drwxr-x--- 5 schulte schulte 4096 Aug 15 18:40 dir
13918312 drwxr-x--- 5 schulte schulte 4096 Aug 15 18:40 dir/.
13918312 drwxr-x--- 5 schulte schulte 4096 Aug 15 18:40 dir/sub1/..
13918312 drwxr-x--- 5 schulte schulte 4096 Aug 15 18:40 dir/sub2/..
13918312 drwxr-x--- 5 schulte schulte 4096 Aug 15 18:40 dir/sub3/..

Formula: Link-of a directory = 2 + number of direct subdirectory

Thus your link-count of 23 should just mean that you have 21 subdirectories in 
your root directory.

There an exception with / - since there's on directory above it both . and .. 
have the same inode.

Since find will not find .., it will only get one entry:

$ sudo find / -xdev -inum 2 -exec ls -lid {} \;
2 drwxr-xr-x 23 root root 4096 Jul 19 10:42 /

For further analysis it would be helpful that you sent us the type of the 
filesystems you are working on and the whole output of the find, not that one 
pipe trought 'wc -l'.

Best regards

Martin



reply via email to

[Prev in Thread] Current Thread [Next in Thread]