歡迎您光臨本站 註冊首頁

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

←手機掃碼閱讀     火星人 @ 2014-03-09 , reply:0

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

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

linux系統中,鏈接分兩種

:一種被稱為硬鏈接(Hard Link),另一種被稱為符號鏈接或軟鏈接(Symbolic Link).

1)默認不帶參數情況下,ln命令創建的是硬鏈接.

2)硬鏈接文件與源文件的inode節點號相同,而軟鏈接文件的

inode節點號與源文件不同.3)ln命令不能對目錄創建硬鏈接,但可以創建軟鏈接,對目錄的軟鏈接會經常被用到.

4)刪除軟鏈接文件,對源文件及硬鏈接文件無任何影響;
5)
刪除文件的硬鏈接文件,對源文件及軟鏈接文件無任何影響;
6)
刪除鏈接文件的原文件,對硬鏈接文件無影響,會導致其軟鏈接失效(紅底白字閃爍狀);


7)
同時刪除原文件及其硬鏈接文件,整個文件才會被真正的刪除.

8)很多硬體設備中的快照功能,使用的就類似硬鏈接的原理.

9)軟連接可以跨文件系統,硬鏈接不可以跨文件系統.

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

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

一個硬鏈接是一個已存在的文件的另一個名字;

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文件系統實戰及實踐精華教案及視頻精講部分


本文出自 「老男孩的linux博客」 博客,請務必保留此出處http://oldboy.blog.51cto.com/2561410/791292


[火星人 ] linux下軟鏈接和硬鏈接的區別(考試題答案系列)已經有695次圍觀

http://coctec.com/docs/linux/show-post-47344.html