之路 on it Road.com
硬链接
每个文件至少使用一个硬链接。
因此,当我们创建新文件时,会创建一个新的目录条目,称为链接计数。
因此,当我们创建指向此文件的新硬链接时,链接计数会增加 1.
- 创建方法
# touch file1 # ls -l -rw-r--r-- 1 root root 0 Sep 23 13:19 file1 # ln file1 file2 # ls -l -rw-r--r-- 2 root root 0 Sep 23 13:19 file1 -rw-r--r-- 2 root root 0 Sep 23 13:19 file2 # ls -li 1282 -rw-r--r-- 2 root 0 root 0 Sep 23 13:19 file1 1282 -rw-r--r-- 2 root 0 root 0 Sep 23 13:19 file2 # find . -inum 1282 ./file1 ./file2
链接数增加 1,每次创建一个新的文件硬链接时,如上所示。
即使我们删除任何一个文件,对另一个文件也没有影响。
只有链接计数减少硬链接不能跨文件系统。
我们不能创建到目录的硬链接。
软链接
如图所示软链接或者符号链接只是指向另一个文件。
它只包含它指向的文件的路径名
- 创建方法
# touch file # ln -s file link # ls -l -rw-r--r-- 1 root root 0 Sep 19 14:41 link lrwxrwxrwx 1 root root 5 Sep 19 15:41 link -> file
上面“ls -l”命令输出中的“l”表示该文件是软链接。
上例中创建的软链接的大小为路径名(文件)中的字符数,为5(可以是绝对的,也可以是相对的)。
如果删除原文件(file)软链接将被视为无用。
软链接可以驻留在不同的文件系统上。
我们也可以创建指向目录的软链接。
日期:2020-09-17 00:14:22 来源:oir作者:oir