9久久伊人精品综合,亚洲一区精品视频在线,成 人免费va视频,国产一区二区三区黄网,99国产精品永久免费视频,亚洲毛片多多影院,精品久久久无码人妻中文字幕,无码国产欧美一区二区三区不卡
學習啦>學習電腦>操作系統>Linux教程>

linux ln命令詳解linux創建軟鏈接和硬鏈接

時間: 志藝942 分享

  ln是linux中又一個非常重要命令,它的功能是為某一個文件在另外一個位置建立一個同步的鏈接,分為軟鏈接、硬鏈接。接下來是小編為大家收集的linux ln命令詳解,希望能幫到大家。

  linux ln命令詳解

  1.命令格式:

  ln [參數][源文件或目錄][目標文件或目錄]

  2.命令功能:

  Linux文件系統中,有所謂的鏈接(link),我們可以將其視為檔案的別名,而鏈接又可分為兩種 : 硬鏈接(hard link)與軟鏈接(symbolic link),硬鏈接的意思是一個檔案可以有多個名稱,而軟鏈接的方式則是產生一個特殊的檔案,該檔案的內容是指向另一個檔案的位置。硬鏈接是存在同一個文件系統中,而軟鏈接卻可以跨越不同的文件系統。

  軟鏈接:

  1.軟鏈接,以路徑的形式存在。類似于Windows操作系統中的快捷方式

  2.軟鏈接可以 跨文件系統 ,硬鏈接不可以

  3.軟鏈接可以對一個不存在的文件名進行鏈接

  4.軟鏈接可以對目錄進行鏈接

  硬鏈接:

  1.硬鏈接,以文件副本的形式存在。但不占用實際空間。

  2.不允許給目錄創建硬鏈接

  3.硬鏈接只有在同一個文件系統中才能創建

  這里有兩點要注意:

  第一,ln命令會保持每一處鏈接文件的同步性,也就是說,不論你改動了哪一處,其它的文件都會發生相同的變化;

  第二,ln的鏈接又分軟鏈接和硬鏈接兩種,軟鏈接就是ln –s 源文件 目標文件,它只會在你選定的位置上生成一個文件的鏡像,不會占用磁盤空間,硬鏈接 ln 源文件 目標文件,沒有參數-s, 它會在你選定的位置上生成一個和源文件大小相同的文件,無論是軟鏈接還是硬鏈接,文件都保持同步變化。

  ln指令用在鏈接文件或目錄,如同時指定兩個以上的文件或目錄,且最后的目的地是一個已經存在的目錄,則會把前面指定的所有文件或目錄復制到該目錄中。若同時指定多個文件或目錄,且最后的目的地并非是一個已存在的目錄,則會出現錯誤信息。

  3.命令參數:

  必要參數:

  -b 刪除,覆蓋以前建立的鏈接

  -d 允許超級用戶制作目錄的硬鏈接

  -f 強制執行

  -i 交互模式,文件存在則提示用戶是否覆蓋

  -n 把符號鏈接視為一般目錄

  -s 軟鏈接(符號鏈接)

  -v 顯示詳細的處理過程

  選擇參數:

  -S “-S<字尾備份字符串> ”或 “--suffix=<字尾備份字符串>”

  -V “-V<備份方式>”或“--version-control=<備份方式>”

  --help 顯示幫助信息

  --version 顯示版本信息

  4.使用實例:

  實例1:給文件創建軟鏈接

  命令:ln -s log2013.log link2013

  輸出:

  復制代碼

  代碼如下:

  [root@localhost test]# ll

  -rw-r--r-- 1 root bin 61 11-13 06:03 log2013.log

  [root@localhost test]# ln -s log2013.log link2013

  [root@localhost test]# ll

  lrwxrwxrwx 1 root root 11 12-07 16:01 link2013 -> log2013.log

  -rw-r--r-- 1 root bin 61 11-13 06:03 log2013.log

  說明:為log2013.log文件創建軟鏈接link2013,如果log2013.log丟失,link2013將失效

  實例2:給文件創建硬鏈接

  命令:ln log2013.log ln2013

  輸出:

  復制代碼

  代碼如下:

  [root@localhost test]# ll

  lrwxrwxrwx 1 root root 11 12-07 16:01 link2013 -> log2013.log

  -rw-r--r-- 1 root bin 61 11-13 06:03 log2013.log

  [root@localhost test]# ln log2013.log ln2013

  [root@localhost test]# ll

  lrwxrwxrwx 1 root root 11 12-07 16:01 link2013 -> log2013.log

  -rw-r--r-- 2 root bin 61 11-13 06:03 ln2013

  -rw-r--r-- 2 root bin 61 11-13 06:03 log2013.log

  說明:為log2013.log創建硬鏈接ln2013,log2013.log與ln2013的各項屬性相同

  實例3:接上面兩實例,鏈接完畢后,刪除和重建鏈接原文件

  命令:ll

  輸出:

  復制代碼

  代碼如下:

  [root@localhost test]# ll

  lrwxrwxrwx 1 root root 11 12-07 16:01 link2013 -> log2013.log

  -rw-r--r-- 2 root bin 61 11-13 06:03 ln2013

  -rw-r--r-- 2 root bin 61 11-13 06:03 log2013.log

  [root@localhost test]# rm -rf log2013.log

  [root@localhost test]# ll

  lrwxrwxrwx 1 root root 11 12-07 16:01 link2013 -> log2013.log

  -rw-r--r-- 1 root bin 61 11-13 06:03 ln2013

  [root@localhost test]# touch log2013.log

  [root@localhost test]# ll

  lrwxrwxrwx 1 root root 11 12-07 16:01 link2013 -> log2013.log

  -rw-r--r-- 1 root bin 61 11-13 06:03 ln2013

  ---xrw-r-- 1 root bin 302108 11-13 06:03 log2012.log

  -rw-r--r-- 1 root root 0 12-07 16:19 log2013.log

  [root@localhost test]# vi log2013.log

  2013-01

  2013-02

  2013-03

  2013-04

  2013-05

  2013-06

  2013-07

  2013-08

  2013-09

  2013-10

  2013-11

  2013-12[root@localhost test]# ll

  lrwxrwxrwx 1 root root 11 12-07 16:01 link2013 -> log2013.log

  -rw-r--r-- 1 root bin 61 11-13 06:03 ln2013

  -rw-r--r-- 1 root root 96 12-07 16:21 log2013.log

  [root@localhost test]# cat link2013

  2013-01

  2013-02

  2013-03

  2013-04

  2013-05

  2013-06

  2013-07

  2013-08

  2013-09

  2013-10

  2013-11

  2013-12

  [root@localhost test]# cat ln2013

  hostnamebaidu=baidu.com

  hostnamesina=sina.com

  hostnames=true

  說明:

  1.源文件被刪除后,并沒有影響硬鏈接文件;軟鏈接文件在centos系統下不斷的閃爍,提示源文件已經不存在

  2.重建源文件后,軟鏈接不在閃爍提示,說明已經鏈接成功,找到了鏈接文件系統;重建后,硬鏈接文件并沒有受到源文件影響,硬鏈接文件的內容還是保留了刪除前源文件的內容,說明硬鏈接已經失效

  實例4:將文件鏈接為另一個目錄中的相同名字

  命令:ln log2013.log test3

  輸出:

  復制代碼

  代碼如下:

  [root@localhost test]# ln log2013.log test3

  [root@localhost test]# ll

  lrwxrwxrwx 1 root root 11 12-07 16:01 link2013 -> log2013.log

  -rw-r--r-- 1 root bin 61 11-13 06:03 ln2013

  -rw-r--r-- 2 root root 96 12-07 16:21 log2013.log

  [root@localhost test]# cd test3

  [root@localhost test3]# ll

  -rw-r--r-- 2 root root 96 12-07 16:21 log2013.log

  [root@localhost test3]# vi log2013.log

  2013-01

  2013-02

  2013-03

  2013-04

  2013-05

  2013-06

  2013-07

  2013-08

  2013-09

  2013-10[root@localhost test3]# ll

  -rw-r--r-- 2 root root 80 12-07 16:36 log2013.log

  [root@localhost test3]# cd ..

  [root@localhost test]# ll

  lrwxrwxrwx 1 root root 11 12-07 16:01 link2013 -> log2013.log

  -rw-r--r-- 1 root bin 61 11-13 06:03 ln2013

  -rw-r--r-- 2 root root 80 12-07 16:36 log2013.log

  [root@localhost test]#

  說明:在test3目錄中創建了log2013.log的硬鏈接,修改test3目錄中的log2013.log文件,同時也會同步到源文件

  實例5:給目錄創建軟鏈接

  命令:ln -sv /opt/soft/test/test3 /opt/soft/test/test5

  輸出:

  復制代碼

  代碼如下:

  [root@localhost test]# ll

  drwxr-xr-x 2 root root 4096 12-07 16:36 test3

  drwxr-xr-x 2 root root 4096 12-07 16:57 test5

  [root@localhost test]# cd test5

  [root@localhost test5]# ll

  lrwxrwxrwx 1 root root 5 12-07 16:57 test3 -> test3

  [root@localhost test5]# cd test3

  -bash: cd: test3: 符號連接的層數過多

  [root@localhost test5]#

  [root@localhost test5]#

  [root@localhost test5]# ll

  lrwxrwxrwx 1 root root 5 12-07 16:57 test3 -> test3

  [root@localhost test5]# rm -rf test3

  [root@localhost test5]# ll

  [root@localhost test5]# ln -sv /opt/soft/test/test3 /opt/soft/test/test5

  創建指向“/opt/soft/test/test3”的符號鏈接“/opt/soft/test/test5/test3”

  [root@localhost test5]# ll

  lrwxrwxrwx 1 root root 20 12-07 16:59 test3 -> /opt/soft/test/test3

  [root@localhost test5]#

  [root@localhost test5]# cd test3

  [root@localhost test3]# ll

  總計 4

  -rw-r--r-- 2 root root 80 12-07 16:36 log2013.log

  [root@localhost test3]# touch log2014.log

  [root@localhost test3]# ll

  總計 4

  -rw-r--r-- 2 root root 80 12-07 16:36 log2013.log

  -rw-r--r-- 1 root root 0 12-07 17:05 log2014.log

  [root@localhost test3]# cd ..

  [root@localhost test5]# cd ..

  說明:

  1.目錄只能創建軟鏈接

  2.目錄創建鏈接必須用絕對路徑,相對路徑創建會不成功,會提示:符號連接的層數過多 這樣的錯誤

  3.在鏈接目標目錄中修改文件都會在源文件目錄中同步變化


看了“linux ln命令詳解”還想看:

1.Linux實用工具的命令行詳解

2.必學100個常用linux命令大全

3.Linux中常用操作命令介紹

4.linux系統命令及其使用詳解

2835931 主站蜘蛛池模板: 四虎影视库国产精品一区| 日夜啪啪一区二区三区| 精品一区二区不卡免费| 精品一二三四区在线观看| 国产精品一区二区三区蜜臀| 口爆少妇在线视频免费观看| 亚洲国产成人不卡高清麻豆| 视频一区二区三区高清在线| 国产极品丝尤物在线观看| 日本一区二区三区有码视频| 九九热免费在线观看视频| 9l精品人妻中文字幕色| 无码专区 人妻系列 在线| 91高清免费国产自产拍| 成人3D动漫一区二区三区| 国产超碰无码最新上传| 日韩人妻无码一区二区三区99| 视频二区中文字幕在线| 四虎精品视频永久免费| 亚洲人妻系列中文字幕| 69天堂人成无码免费视频| 日韩中文字幕V亚洲中文字幕| 久久大香伊蕉在人线免费AV| 亚洲VA成无码人在线观看天堂| 国产亚洲999精品AA片在线爽| 久久精品国产亚洲夜色AV网站| 日韩人妻无码精品久久| 亚洲欧美在线观看一区二区| 精品国产色情一区二区三区 | 国产男女猛烈无遮挡免费视频网址| 国产免费久久精品99reswag| 国产福利酱国产一区二区| 精品熟女少妇免费久久| 亚洲一区二区三区18禁| 毛片无遮挡高清免费| 精品国产女同疯狂摩擦2| 国产精品久久久一区二区三区 | 农村熟女大胆露脸自拍| 国产一级三级三级在线视| 欧美视频在线播放观看免费福利资源| 国产精品亚洲А∨天堂免下载|