天天看點

軟連結和硬連結

1、軟連結   類似于windows裡的快捷方式,它存放的是一個檔案的路徑,能節省很大的空間;可跨分區連結

注:最好寫絕對路徑

檔案和目錄都可以做軟連結

#舉例

[root@wy ~]# ln -s /root/11.txt  /tmp/23.txt

[root@wy ~]# ls -l /tmp/23.txt

lrwxrwxrwx 1 root root 12 9月  21 19:54 /tmp/23.txt -> /root/11.txt

2、硬連結    它實質是給某一個檔案做了一個替身,讓它們同時指向了一個inode(inode是檔案或目錄它的一個核心的

中繼資料,是記錄資料很重要的一個資訊)。

  注:一個inode可以對應多個檔案,但一個檔案不能對應多個inode。

     目錄不可以做硬連結。而且隻能在同一個分區下。

     删除一個,另一個不會受影響。

[root@wy ~]# ln /root/11.txt  /tmp/12.txt

[root@wy ~]# ls -li /root/11.txt  /tmp/12.txt

  404005 -rwxrwxrwx 2 root root 5 9月  21 19:35 /root/11.txt

  404005 -rwxrwxrwx 2 root root 5 9月  21 19:35 /tmp/12.txt

#不能跨分區

[root@wy ~]# ln /tmp/12.txt /boot/22.txt

ln: 建立硬連結"/boot/22.txt" => "/tmp/12.txt": 無效的跨裝置連接配接