Linux鏈接命令的實(shí)例詳解
Linux鏈接命令的實(shí)例詳解
一 語(yǔ)法
ln -s [源文件] [目標(biāo)文件] 命令英文含義:link 功能描述:生成鏈接文件 選項(xiàng):-s 創(chuàng)建軟鏈接
二 硬鏈接特征
原文件和硬鏈接文件刪除其中任何一個(gè)都沒(méi)問(wèn)題。
三 硬鏈接實(shí)戰(zhàn)
[root@localhost ~]# cd test [root@localhost test]# ls bcd [root@localhost test]# ln bcd abc.hard [root@localhost test]# ll total 0 -rw-r--r--.2 root root 0Jul1219:31 abc.hard -rw-r--r--.2 root root 0Jul1219:31 bcd [root@localhost test]# vi bcd [root@localhost test]# cat abc.hard qwer [root@localhost test]# echo "dfd">> abc.hard [root@localhost test]# cat bcd qwer dfd [root@localhost test]# ls -i 67170460 abc.hard 67170460 bcd [root@localhost test]# rm bcd rm: remove regular file ?.cd?. y [root@localhost test]# cat abc.hard qwer dfd [root@localhost test]# ll -i total 4 67170460-rw-r--r--.1 root root 10Jul1220:39 abc.hard
四 軟鏈接特征
1、把原文件刪除,軟鏈接文件無(wú)法使用。
2、雖然軟鏈接文件的權(quán)限是777,但真正的權(quán)限還是由原文件決定。
3、創(chuàng)建軟鏈接時(shí),如果原文件和目標(biāo)文件在一個(gè)目錄下,不用寫(xiě)絕對(duì)路徑,否則原文件和目標(biāo)文件必須寫(xiě)絕對(duì)路徑。所以原文件一定要寫(xiě)絕對(duì)路徑。
五 實(shí)戰(zhàn)
[root@localhost test]# ls abc [root@localhost test]# ln -s abc abc.soft [root@localhost test]# ll total 0 -rw-r--r--.1 root root 0Jul1220:42 abc lrwxrwxrwx.1 root root 3Jul1220:55 abc.soft -> abc [root@localhost test]#in abc abc.hard -bash: syntax error near unexpected token `in' [root@localhost test]# ln abc abc.hard [root@localhost test]# ll total 0 -rw-r--r--. 2 root root 0 Jul 12 20:42 abc -rw-r--r--. 2 root root 0 Jul 12 20:42 abc.hard lrwxrwxrwx. 1 root root 3 Jul 12 20:55 abc.soft -> abc [root@localhost test]# ls -i 67170460 abc 67170460 abc.hard 67170462 abc.soft [root@localhost test]# echo 111 >>abc [root@localhost test]# cat abc.soft 111 [root@localhost test]# cat abc.hard 111 [root@localhost test]# echo 222 >> abc.soft [root@localhost test]# cat abc 111 222 [root@localhost test]# cat abc.soft 111 222 [root@localhost test]# rm -rf abc [root@localhost test]# ll total 4 -rw-r--r--. 1 root root 8 Jul 12 20:59 abc.hard lrwxrwxrwx. 1 root root 3 Jul 12 20:55 abc.soft -> abc [root@localhost test]# cat abc.hard 111 222 [root@localhost test]# rm -rf abc.soft [root@localhost test]# ll total 4 -rw-r--r--. 1 root root 8 Jul 12 20:59 abc.hard [root@localhost test]# touch abc [root@localhost test]# ln -s abc.soft [root@localhost test]# ls abc abc.hard abc.soft [root@localhost test]# ll -i total 4 67170462 -rw-r--r--. 1 root root 0 Jul 12 21:01 abc 67170460 -rw-r--r--. 1 root root 8 Jul 12 20:59 abc.hard 67170463 lrwxrwxrwx. 1 root root 8 Jul 12 21:01 abc.soft -> abc.soft [root@localhost test]# rm -rf * [root@localhost test]# ll total 0 [root@localhost test]# touch abc [root@localhost test]# ln -s abc abc.soft [root@localhost test]# ll total 0 -rw-r--r--. 1 root root 0 Jul 12 21:05 abc lrwxrwxrwx. 1 root root 3 Jul 12 21:05 abc.soft -> abc [root@localhost test]# ln -s abc /tmp/ab.soft [root@localhost test]# ll /tmp total 0 lrwxrwxrwx. 1 root root 3 Jul 12 21:06 ab.soft -> abc drwxr-xr-x. 3 root root 16 Jul 12 19:33 japan [root@localhost test]# ll /tmp total 0 lrwxrwxrwx. 1 root root 3 Jul 12 21:06 ab.soft -> abc drwxr-xr-x. 3 root root 16 Jul 12 19:33 japan [root@localhost test]# rm -rf /tmp/ab.soft [root@localhost test]# ln -s /root/test/abc /tmp/ab.soft [root@localhost test]# ll /tmp total 0 lrwxrwxrwx. 1 root root 14 Jul 12 21:08 ab.soft -> /root/test/abc drwxr-xr-x. 3 root root 16 Jul 12 19:33 japan
六 硬鏈接和軟鏈接文件訪問(wèn)示意圖
以上就是Linux鏈接命令的詳解,如有疑問(wèn)請(qǐng)留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!
相關(guān)文章
Linux BASH多進(jìn)程并行處理的方法實(shí)現(xiàn)
Linux下BASH多進(jìn)程并行處理的實(shí)現(xiàn)代碼,需要的朋友可以參考下2013-01-01bash shell和dash shell的區(qū)別詳解
本文主要介紹了bash shell和dash shell的區(qū)別詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-05-05Linux命令學(xué)習(xí)之用戶切換su,sudo命令詳解
在操作過(guò)程中需要使用特定的用戶進(jìn)行特定的操作,多數(shù)情況下是因?yàn)闄?quán)限,比如要修改一個(gè)文件,只有root用戶有權(quán)限修改,那么就要切換到root用戶下進(jìn)行操作,本文給大家講解Linux命令學(xué)習(xí)之用戶切換su,sudo命令,感興趣的朋友跟隨小編一起看看吧2023-02-02shell 中小括號(hào)、中括號(hào)及大括號(hào)的區(qū)別解析
這篇文章主要介紹了shell 中小括號(hào),中括號(hào),大括號(hào)的區(qū)別,針對(duì)每種括號(hào)給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-10-10shell產(chǎn)生隨機(jī)數(shù)七種方法的實(shí)現(xiàn)
這篇文章主要介紹了shell產(chǎn)生隨機(jī)數(shù)七種方法的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-12-12Shell腳本實(shí)現(xiàn)檢測(cè)Cygwin最快的鏡像站點(diǎn)
這篇文章主要介紹了Shell腳本實(shí)現(xiàn)檢測(cè)Cygwin最快的鏡像站點(diǎn),本文的原理和腳本也可適用其它軟件比如apache、nginx等開(kāi)源軟件,需要的朋友可以參考下2015-04-04Linux?自動(dòng)化構(gòu)建工具make/Makefile的使用詳解
這篇文章主要介紹了Linux?自動(dòng)化構(gòu)建工具?make/Makefile,要如何編譯.c文件,關(guān)鍵就在于Makefile是怎么寫(xiě)的,下面我們主要介紹這兩者的使用,需要的朋友可以參考下2022-04-04