软链接(符号链接):
1、可以在不同的文件系统中进行,相当于快捷方式
2、删除源文件后,快捷方式将不能链接到源文件
[root@localhost ~]# cd /tmp
[root@localhost tmp]# du -sb;df -i #du -sb是计算整个/tmp目录下有多少 bytes的容量
5329.
[root@localhost tmp]# cd
[root@localhost ~]# touch rlj
[root@localhost ~]# ln -s /root/rlj /tmp/rlj.lnk
[root@localhost ~]# cd /tmp
[root@localhost tmp]# du -sb;df -i #软链接会占用inode数
5338.
[root@localhost 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
[root@localhost tmp]# cd
[root@localhost ~]# ln -s rlj /etc/rlj.lnk #此处rlj应该跟绝对路径,否则链接的文件将出现闪烁的状态
[root@localhost ~]# 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
[root@localhost ~]# echo "this is a rlj file" >> rlj
[root@localhost ~]# cat rlj
this is a rlj file
[root@localhost ~]# rm -f rlj
[root@localhost ~]# ll rlj
ls: cannot access rlj: No such file or directory
[root@localhost ~]# vim /tmp/rlj.lnk #可看出源档案被删除后又重新建立了此档案
~
~
"rlj.lnk" [New File]
[root@localhost ~]# mkdir rlj
[root@localhost ~]# ln -s /root/rlj /var/ #为目录建立软链接
[root@localhost ~]# ll /var/rlj
lrwxrwxrwx. 1 root root 9 Oct 6 16:43 /var/rlj -> /root/rlj
[root@localhost ~]# rm -fr rlj
[root@localhost ~]# ll /var/rlj
lrwxrwxrwx. 1 root root 9 Oct 6 16:43 /var/rlj -> /root/rlj
硬链接:
1、不能对目录进行硬件链接
2、不能跨越不同的文件系统
[root@localhost ~]# touch ylj
[root@localhost ~]# vim ylj
[root@localhost ~]# ln ylj /tmp
[root@localhost ~]# ln ylj /
[root@localhost ~]# cd /tmp
[root@localhost 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
[root@localhost tmp]# vim ylj
[root@localhost tmp]# cat /root/ylj
this is a ylj file
ylj don't support directory.
[root@localhost tmp]# cat /ylj
this is a ylj file
ylj don't support directory.
[root@localhost tmp]# rm -f ylj
[root@localhost 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
[root@localhost tmp]# mkdir yl
[root@localhost tmp]# ln yl / #硬链接对目录不生效
ln: ‘yl’: hard link not allowed for directory
转载于:https://blog.51cto.com/zjzd86/1700591