ln指令可以建立硬連結:
文法格式:
ln 源檔案 目标檔案
檔案名1-》inode1-》blockA
檔案名2-》inode1-》blockA
[root@localhost ~]# ln a.txt b.txt
[root@localhost ~]# ll -i a.txt b.txt
36433003 -rw-r--r-- 2 root root 10 Feb 24 09:05 a.txt
36433003 -rw-r--r-- 2 root root 10 Feb 24 09:05 b.txt
[root@localhost ~]# rm -rf a.txt
[root@localhost ~]# cat b.txt
aaaa
bbbb
#源檔案被删除,不影響連結檔案的正常使用
[root@localhost ~]# mkdir test
[root@localhost ~]# ln test/ 123
ln: ‘test/’: hard link not allowed for directory
#硬連結不能針對目錄建立
[root@localhost ~]# ln /boot/grub2/grub.cfg grub.cfg
ln: failed to create hard link ‘grub.cfg’ => ‘/boot/grub2/grub.cfg’: Invalid cross-device link
#硬連結不允許跨分區建立
總結: 硬連結特點,建立時,不能跨分區,不能給檔案夾。
軟連結:相當于windows中的快捷方式
[root@localhost ~]# ln -s b.txt c.txt
[root@localhost ~]# rm -rf b.txt
[root@localhost ~]# cat c.txt
cat: c.txt: No such file or directory
#源檔案被删除,連結檔案失效
[root@localhost ~]# ln -s test/ 123
#能針對目錄建立
[root@localhost ~]# ln -s /boot/grub2/grub.cfg grub.cfg
#能跨分區建立
例:檢視目錄的連結數
[root@localhost ~]# ll -d test/
drwxr-xr-x 2 root root 6 Feb 24 09:10 test/
[root@localhost ~]# ll -di test/
50599109 drwxr-xr-x 2 root root 6 Feb 24 09:10 test/
[root@localhost test]# ll -di .
50599109 drwxr-xr-x 2 root root 6 Feb 24 09:10 .
[root@localhost xuegod]# ll -di ..
50599109 drwxr-xr-x 3 root root 19 Feb 24 09:23 ..
本文轉自信自己belive51CTO部落格,原文連結: http://blog.51cto.com/11638205/2048925,如需轉載請自行聯系原作者