linux下軟連接和硬連接的區別(考試題答案系列)

說明:本文爲老男孩linux培訓某節課前考試試題及答案分享博文內容的一部分,也是獨立成題的,你能夠點下面地址查看所有的內容信息。
http://oldboy.blog.51cto.com/2561410/791245

2.
描述linux下軟連接和硬連接的區別。(記時2分鐘) node

linux系統中,連接分兩種 :一種被稱爲硬連接(Hard Link),另外一種被稱爲符號連接或軟連接(Symbolic Link)。 linux

1)默認不帶參數狀況下,ln命令建立的是硬連接。 運維

2)硬連接文件與源文件的inode節點號相同,而軟連接文件的inode節點號與源文件不一樣。3)ln命令不能對目錄建立硬連接,但能夠建立軟連接,對目錄的軟連接會常常被用到。 ide

4)刪除軟連接文件,對源文件及硬連接文件無任何影響;
5)
刪除文件的硬連接文件,對源文件及軟連接文件無任何影響;
6)
刪除連接文件的原文件,對硬連接文件無影響,會致使其軟連接失效(紅底白字閃爍狀);
7)
同時刪除原文件及其硬連接文件,整個文件纔會被真正的刪除。
ui

8)不少硬件設備中的快照功能,使用的就相似硬連接的原理。 spa

9)軟鏈接能夠跨文件系統,硬連接不能夠跨文件系統。 rest

附錄一:info ln結果摘錄及老男孩老師簡譯參考 orm

A "hard link" is another name for an existing file; 視頻

一個硬連接是一個已存在的文件的另外一個名字; blog

the link and the original are indistinguishable. 

這個連接和源文件很難發現有不一樣的地方(除了名稱不同)。

Technically speaking, they share the same inode, and the inode contains all the information about a file--indeed, it is not incorrect to say that the inode _is_ the file.

從技術上講,他們共享同一個inode節點號,而且這個節點包含一個文件的全部真實信息(各類屬性信息,非文件名和文件內容),把inode當成是文件的說法是不對的。

you cannot make a hard link to a directory, and hard links cannot cross file system boundaries.

你不能爲一個目錄建立硬連接,而且硬連接不能穿越文件系統邊界。

 (These restrictions are not mandated by POSIX, however.)

然而,上述限制在POSIX中是不被限制的。

 

   "Symbolic links" ("symlinks" for short), on the other hand, are a special file type (which not all kernels support: System V release 3 (and older) systems lack symlinks) in which the link file actually refers to a different file, by name.  When most operations (opening,reading, writing, and so on) are passed the symbolic link file, the kernel automatically "dereferences" the link and operates on the target of the link.  But some operations (e.g., removing) work on the link

file itself, rather than on its target. 

符號連接是一個特殊的文件類型,這不是全部的內核都支持的,System V release 3或更老的系統就缺少符號連接,這個符號鏈接文件其實是經過名字指向一個不一樣的文件(和源文件是不一樣的文件),當打開,讀取,寫入等等大多數操做時,會經過符號連接連接到文件,內核自動找到連接而且操做連接的源,可是一些操做(如:刪除)等工做是針對連接自身的,而不是連接的源。

 

更詳細的描述及實踐案例見:

老男孩Linux運維實戰培訓-Linux的硬連接和軟連接知識和實踐教案和視頻精講
    老男孩Linux運維實戰培訓-Linux文件和目錄的屬性及權限-001.rar
    老男孩Linux運維實戰培訓-Linux文件系統實戰及實踐精華教案及視頻精講部分

相關文章
相關標籤/搜索