软链接(符号链接):
1、可以在不同的文件系统中进行,相当于快捷方式
2、删除源文件后,快捷方式将不能链接到源文件
[[email protected] ~]# cd /tmp
[[email protected] tmp]# du -sb;df -i #du -sb是计算整个/tmp目录下有多少 bytes的容量
5329.
[[email protected] tmp]# cd
[[email protected] ~]# touch rlj
[[email protected] ~]# ln -s /root/rlj /tmp/rlj.lnk
[[email protected] ~]# cd /tmp
[[email protected] tmp]# du -sb;df -i #软链接会占用inode数
5338.
[[email protected] tmp]# ll /root/rlj ./rlj.lnk
lrwxrwxrwx. 1 root root 9 Oct 6 16:37 ./rlj.lnk -> /root/rlj
-rw-r--r--. 1 root root 0 Oct 6 16:37 /root/rlj
[[email protected] tmp]# cd
[[email protected] ~]# ln -s rlj /etc/rlj.lnk #此处rlj应该跟绝对路径,否则链接的文件将出现闪烁的状态
[[email protected] ~]# ll rlj /etc/rlj.lnk
lrwxrwxrwx. 1 root root 3 Oct 6 16:40 /etc/rlj.lnk -> rlj
-rw-r--r--. 1 root root 0 Oct 6 16:37 rlj
[[email protected] ~]# echo "this is a rlj file" >> rlj
[[email protected] ~]# cat rlj
this is a rlj file
[[email protected] ~]# rm -f rlj
[[email protected] ~]# ll rlj
ls: cannot access rlj: No such file or directory
[[email protected] ~]# vim /tmp/rlj.lnk #可看出源档案被删除后又重新建立了此档案
~
~
"rlj.lnk" [New File]
[[email protected] ~]# mkdir rlj
[[email protected] ~]# ln -s /root/rlj /var/ #为目录建立软链接
[[email protected] ~]# ll /var/rlj
lrwxrwxrwx. 1 root root 9 Oct 6 16:43 /var/rlj -> /root/rlj
[[email protected] ~]# rm -fr rlj
[[email protected] ~]# ll /var/rlj
lrwxrwxrwx. 1 root root 9 Oct 6 16:43 /var/rlj -> /root/rlj
硬链接:
1、不能对目录进行硬件链接
2、不能跨越不同的文件系统
[[email protected] ~]# touch ylj
[[email protected] ~]# vim ylj
[[email protected] ~]# ln ylj /tmp
[[email protected] ~]# ln ylj /
[[email protected] ~]# cd /tmp
[[email protected] tmp]# ll -hi ylj /root/ylj /ylj #以人类可读性方式显示并给出连接的档案数,还可以看出它们的inode数相同均为204670563
204670563 -rw-r--r--. 3 root root 19 Oct 6 15:55 /root/ylj
204670563 -rw-r--r--. 3 root root 19 Oct 6 15:55 ylj
204670563 -rw-r--r--. 3 root root 19 Oct 6 15:55 /ylj
[[email protected] tmp]# vim ylj
[[email protected] tmp]# cat /root/ylj
this is a ylj file
ylj don‘t support directory.
[[email protected] tmp]# cat /ylj
this is a ylj file
ylj don‘t support directory.
[[email protected] tmp]# rm -f ylj
[[email protected] tmp]# ll -hi /ylj /root/ylj
204670563 -rw-r--r--. 2 root root 48 Oct 6 15:57 /root/ylj
204670563 -rw-r--r--. 2 root root 48 Oct 6 15:57 /ylj
[[email protected] tmp]# mkdir yl
[[email protected] tmp]# ln yl / #硬链接对目录不生效
ln: ‘yl’: hard link not allowed for directory