<分区>
Possible Duplicate:
How to check whether two file names point to the same physical file
我如何知道两个硬链接(hard link)是否连接到 Linux 中 C 中的一个文件。
谢谢。
<分区>
Possible Duplicate:
How to check whether two file names point to the same physical file
我如何知道两个硬链接(hard link)是否连接到 Linux 中 C 中的一个文件。
谢谢。
最佳答案
使用 stat() or fstat()两个路径的功能。如果在返回的结构中 st_dev 和 st_ino 字段相同,则路径引用相同的文件系统对象。
编辑:
请注意,您需要检查 st_dev 和 st_ino。否则,您将冒着匹配不同文件系统中恰好具有相同 inode 号的两个文件的风险。如果您在两个挂载点上运行 stat
,您可能会看到这一点:
$ stat / /boot | grep Device
Device: 903h/2307d Inode: 2 Links: 23
Device: 902h/2306d Inode: 2 Links: 3
您可以在输出中清楚地看到相同的 inode 编号。
关于c - Linux 中是否有两个硬链接(hard link)连接到一个文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4361318/