系統(tǒng)之家 - 系統(tǒng)光盤(pán)下載網(wǎng)站!

當(dāng)前位置:系統(tǒng)之家 > 系統(tǒng)教程 > Linux ln命令操作

Linux ln命令操作指南(2)

時(shí)間:2015-02-26 17:31:39 作者:qipeng 來(lái)源:系統(tǒng)之家 1. 掃描二維碼隨時(shí)看資訊 2. 請(qǐng)使用手機(jī)瀏覽器訪問(wèn): https://m.xitongzhijia.net/xtjc/20150226/39107.html 手機(jī)查看 評(píng)論

  如果修改檔案的內(nèi)容,源文件和hard link文件對(duì)應(yīng)的block區(qū)域內(nèi)容都會(huì)被修改,從而保持一致性。

  # touch /tmp/file

  # echo “hard link test” 》 /tmp/file

  # cat /tmp/file

  hard link test

  # ln /tmp/file /tmp/hard_link

  # ls -lhi /tmp/file

  7996 -rw-r--r-- 2 root root 15 Jan 1 00:25 /tmp/file

  # ls -lhi /tmp/hard_link

  7996 -rw-r--r-- 2 root root 15 Jan 1 00:25 /tmp/hard_link

  # cat /tmp/hard_link

  hard link test

  #

  # echo “hard link test 2” 》 /tmp/file

  # cat /tmp/file

  hard link test 2

  # cat /tmp/hard_link

  hard link test 2

  #

  # echo “hard link test 3” 》 /tmp/hard_link

  # cat /tmp/file

  hard link test 3

  # cat /tmp/hard_link

  hard link test 3

  #

  4. 刪除hard link或者刪除源文件,實(shí)際上只是刪除其中其中一份block區(qū)域。

  可以看到,雖然源文件被刪除(實(shí)際上只是刪除了源文件對(duì)應(yīng)的block區(qū)),但是

  inode仍然還在,所以仍然可以透過(guò)hard link檔案來(lái)訪問(wèn)源文件的內(nèi)容。

  到了這里,就可以理解為什么inode信息中不包含文件名了;

  因?yàn)槿绻募畔趇node中,并且創(chuàng)建了hard link,此時(shí)為何還需要兩塊不同的block區(qū)域

  來(lái)儲(chǔ)存文件信息呢?進(jìn)而hard link還有什么意義呢?

  # rm /tmp/file

  # cat /tmp/file

  cat: can’t open ‘/tmp/file’: No such file or directory

  #

  # cat /tmp/hard_link

  hard link test 3

  #

  # ls -hli /tmp/hard_link

  7996 -rw-r--r-- 1 root root 17 Jan 1 00:29 /tmp/hard_link

  #

  5. 為目錄創(chuàng)建symbolic link?

  因?yàn)樾陆ǖ膕ymbolic link目錄與源目錄是同一個(gè)inode,所以對(duì)這兩個(gè)目錄的訪問(wèn)具有完全相同的表現(xiàn)。

  # mkdir /tmp/directory

  # ln -fs /tmp/directory/ /tmp/dir_sym_link

  #

  # ls -hdi /tmp/directory/

  14018 /tmp/directory/

  # ls -hdi /tmp/dir_sym_link/

  14018 /tmp/dir_sym_link/

  #

  # touch /tmp/directory/file

  # ls -hil /tmp/directory/file

  14781 -rw-r--r-- 1 root root 0 Jan 1 00:47 /tmp/directory/file

  # ls -hil /tmp/dir_sym_link/file

  14781 -rw-r--r-- 1 root root 0 Jan 1 00:47 /tmp/dir_sym_link/file

  #

  # echo “directory symbolic test” 》 /tmp/dir_sym_link/file

  # cat /tmp/dir_sym_link/file

  directory symbolic test

  # cat /tmp/directory/file

  directory symbolic test

  #

  6. 為目錄創(chuàng)建hard link?

  從結(jié)果看,為目錄創(chuàng)建hard link失敗了。

  # ln /tmp/directory/ /tmp/dir_hard_link

  ln: /tmp/dir_hard_link: Operation not permitted

  上面就是Linux使用ln命令的方法介紹了,本文一共介紹了ln命令的六個(gè)實(shí)例,可以知道ln命令可以創(chuàng)建hard link,為目錄創(chuàng)建symbolic link等。

標(biāo)簽 命令

發(fā)表評(píng)論

0

沒(méi)有更多評(píng)論了

評(píng)論就這些咯,讓大家也知道你的獨(dú)特見(jiàn)解

立即評(píng)論

以上留言僅代表用戶個(gè)人觀點(diǎn),不代表系統(tǒng)之家立場(chǎng)

其他版本軟件

熱門(mén)教程

人氣教程排行

Linux系統(tǒng)推薦

掃碼關(guān)注
掃碼關(guān)注

掃碼關(guān)注 官方交流群 軟件收錄