Are two hard channels linked to the same file in Linux?

Possible duplicate:
How to check if two file names point to the same physical file

How to find out if two hard channels are associated with the same file with C in Linux.

Thank.

+3
source share
4 answers

Use stator fstat. The structure statthey populate contains the inode number. If the two are connected, the fields st_inomust have the same value.

Since inodes are unique only to the device, you also need to check the device identifier ( st_dev).

+3
source

stat() fstat() . st_dev st_ino , .

EDIT:

, st_dev, st_ino. , . , stat :

$ stat / /boot | grep Device
Device: 903h/2307d  Inode: 2           Links: 23
Device: 902h/2306d  Inode: 2           Links: 3

inode .

+7

stat() fstat() , st_nlink, , . , , .

+2
source

You can also use

$ ls -i

It lists the inode number, which is the final unique identifier for the file.

0
source

Source: https://habr.com/ru/post/1778626/


All Articles