天天看點

軟硬方式連結

在 Linux 系統中的 ln 指令能夠讓使用者建立出兩種不同類型的檔案快捷方式,一定要注意區分:

硬連結 (hard link) 可以被了解為一個 “ 指向原始檔案 inode 的指針 ” ,系統不為它配置設定獨立的 inode

與檔案,是以實際上來講硬連結檔案與原始檔案其實是同一個檔案,隻是名字不同。于是每添加一個硬連結,

該檔案的 inode 連接配接數就會增加 1 ,直到該檔案的 inode 連接配接數歸 0 才是徹底删除。概括來說因為硬鍊

接實際就是指向原檔案 inode 的指針,即便原始檔案被删除依然可以通過連結檔案通路,但是不能跨檔案

系統也不能連結目錄檔案。

  • 建立硬連結 :“ln 檔案名 連結名 ”
  • 建立軟連結 :“ln -s 檔案名 連接配接名 ”
參數 作用
-s 建立"符号連結"(預設是硬連結)
-f 強制建立檔案或目錄的連結
-i 覆寫前先詢問
-v 顯示建立連結的過程
[root@rhel7 tmp]# echo this is a > file
[root@rhel7 tmp]# cat file
this is a
[root@rhel7 tmp]# ll file
-rw-r--r--. 1 root root 10 Jun 22 16:02 file
[root@rhel7 tmp]# ln file fileh
[root@rhel7 tmp]# ll file fileh
[root@rhel7 tmp]# ll file fileh files -i
52973928 -rw-r--r--. 2 root root 10 Jun 22 16:02 file
52973928 -rw-r--r--. 2 root root 10 Jun 22 16:02 fileh
52973930 lrwxrwxrwx. 1 root root 4 Jun 22 16:03 files -> filefile