硬连接和软连接的区别与做用

软连接(符号连接):node

一、能够在不一样的文件系统中进行,至关于快捷方式vim

二、删除源文件后,快捷方式将不能连接到源文件ide

[root@localhost ~]# cd /tmpthis

[root@localhost tmp]# du -sb;df -i    #du -sb是计算整个/tmp目录下有多少 bytes的容量spa

5329.it

[root@localhost tmp]# cdclass

[root@localhost ~]# touch rljfile

[root@localhost ~]# ln -s /root/rlj /tmp/rlj.lnk硬件

[root@localhost ~]# cd /tmpim

[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



硬连接:

一、不能对目录进行硬件连接

二、不能跨越不一样的文件系统

[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

相关文章
相关标签/搜索