总结软连接和硬链接区别,实例操作说明
硬链接:
本质时对同一个文件起多个文件名。所以表现为一个inode号可以对应多个文件名。
实例:
[root@iZuf69aakqlvmt4fqvqcrxZ test]# ll -i
total 0
1057905 -rw-r–r-- 1 root root 0 Nov 10 14:58 test.txt
[root@iZuf69aakqlvmt4fqvqcrxZ test]# ln test.txt test1.txt
[root@iZuf69aakqlvmt4fqvqcrxZ test]# ll -i
total 0
1057905 -rw-r–r-- 2 root root 0 Nov 10 14:58 test1.txt
1057905 -rw-r–r-- 2 root root 0 Nov 10 14:58 test.txt
[root@iZuf69aakqlvmt4fqvqcrxZ test]# rm test1.txt
rm: remove regular empty file ‘test1.txt’? y
[root@iZuf69aakqlvmt4fqvqcrxZ test]# ll -i
total 0
1057905 -rw-r–r-- 1 root root 0 Nov 10 14:58 test.txt
特性:
1.文件有相同的inode和data block
2.只能对已存在的文件创建
3.不能夸分区创建
4.不能对目录进行创建,只可对文件创建
5.删除一个硬链接文件不影响其他有相同inode号的文件
软链接:
软连接就是一个普通文件,只是数据块内容有点特殊。软链接有着自己的inode号以及用户数据块。
特点:
1.有自己的文件属性及权限等
2.可对不存在的文件或目录创建软链接
3.可跨分区创建
4.可对文件或目录创建
5.创建时,链接计数不会增加
6.删除软链接并不影响被指向的文件,但若被指向的原文件被删除,则相关软链接被称为死链接,若被指向路劲文件被重新创建,死链接可恢复为正常的软链接
实例:
[root@iZuf69aakqlvmt4fqvqcrxZ test]# ll
total 0
-rw-r–r-- 1 root root 0 Nov 10 14:58 test.txt
[root@iZuf69aakqlvmt4fqvqcrxZ test]# ln -s test.txt test.txt.lnk
[root@iZuf69aakqlvmt4fqvqcrxZ test]# ll
total 0
-rw-r–r-- 1 root root 0 Nov 10 14:58 test.txt
lrwxrwxrwx 1 root root 8 Nov 10 15:14 test.txt.lnk -> test.txt
[root@iZuf69aakqlvmt4fqvqcrxZ test]# rm test.txt
rm: remove regular empty file ‘test.txt’? y
[root@iZuf69aakqlvmt4fqvqcrxZ test]# ll
total 0
lrwxrwxrwx 1 root root 8 Nov 10 15:14 test.txt.lnk -> test.txt
[root@iZuf69aakqlvmt4fqvqcrxZ test]# touch test.txt
[root@iZuf69aakqlvmt4fqvqcrxZ test]# ll
total 0
-rw-r–r-- 1 root root 0 Nov 10 15:15 test.txt
lrwxrwxrwx 1 root root 8 Nov 10 15:14 test.txt.lnk -> test.txt