use*_*130 1 linux symlink hardlink
我理解Linux中的硬链接和软链接之间的区别,但是我无法理解这个问题:硬链接是否可以指向已删除的文件?为什么或者为什么不?我认为可以,但我不确定.解释会很棒.谢谢!
考虑一个例子,
$ touch aFile.txt
$ ls -i aFile.txt # -i is the option to look at the inode of a file
2621520 aFile.txt
$ ln aFile.txt 2File.txt # Hardlink the file to another one
$ ls -i 2File.txt
2621520 2File.txt # inode is pointing to the same location
$ rm aFile.txt # Original file gets deleted
$ ls 2File.txt
2File.txt
$ ls -i 2File.txt # inode survives and still pointing to the same location
2621520 2File.txt
Run Code Online (Sandbox Code Playgroud)
在这里阅读更多inodes.
编辑:
stat可以显示文件的硬链接数.您可以使用-c '%h'选项查看:
# after the hardlink to 2File.txt
$ stat -c '%h' aFile.txt
2
Run Code Online (Sandbox Code Playgroud)