linux的软连接命令(文件夹建立软连接)(Linux.org)
前言
- 文章來(lái)源:CSDN@LawsonAbs
1.軟連接
1.1 創(chuàng)建語(yǔ)法
ln -s target source
解釋下:
ln -s:表示創(chuàng)建一個(gè)軟連接;
target:表示目標(biāo)文件(夾)【即被指向的文件(夾)】
source:表示當(dāng)前目錄的軟連接名。【源文件(夾)】
1.2 具體示例
- step 1.創(chuàng)建測(cè)試文件及文件夾
[root@server6 ~]# mkdir test_chk
[root@server6 ~]# touch test_chk/test.txt
[root@server6 ~]# echo "hello spark" > test_chk/test.txt
[root@server6 ~]# cat test_chk/test.txt
hello spark
[root@server6 ~]# ll
總用量 84
-rw-------. 1 root root 1257 6月 16 01:17 anaconda-ks.cfg
drwxr-xr-x. 25 root root 4096 11月 1 10:28 azkabanJob
-rw-r--r--. 1 root root 67322 11月 4 10:24 azkabanJob.zip
drwxr-xr-x. 4 root root 37 7月 13 11:01 hadoop_temp
-rw-r--r--. 1 root root 54 7月 4 14:11 HelloLinux.txt
drwxr-xr-x. 2 root root 22 11月 4 10:41 test_chk
-rw-r--r--. 1 root root 67 10月 8 15:52 zookeeper.out
[root@server6 ~]# ln -s test_chk/ test_chk_ln
[root@server6 ~]# ll
總用量 84
-rw-------. 1 root root 1257 6月 16 01:17 anaconda-ks.cfg
drwxr-xr-x. 25 root root 4096 11月 1 10:28 azkabanJob
-rw-r--r--. 1 root root 67322 11月 4 10:24 azkabanJob.zip
drwxr-xr-x. 4 root root 37 7月 13 11:01 hadoop_temp
-rw-r--r--. 1 root root 54 7月 4 14:11 HelloLinux.txt
drwxr-xr-x. 2 root root 22 11月 4 10:41 test_chk
lrwxrwxrwx. 1 root root 9 11月 4 10:42 test_chk_ln -> test_chk/
-rw-r--r--. 1 root root 67 10月 8 15:52 zookeeper.out
[root@server6 ~]# cd test_chk_ln/
[root@server6 test_chk_ln]# ll
總用量 4
-rw-r--r--. 1 root root 12 11月 4 10:41 test.txt
[root@server6 test_chk_ln]# cat test.txt
hello spark
[root@server6 test_chk_ln]# ll
總用量 4
-rw-r--r--. 1 root root 12 11月 4 10:41 test.txt
[root@server6 test_chk_ln]# cat test.txt
hello spark
2.注意
2.1 創(chuàng)建軟連接時(shí),不用創(chuàng)建文件夾。
2.2 命令示例解釋
執(zhí)行的命令是: ln -s /storage/lawson/scores scor
其含義就是:將scor指向 /storage/lawson/scores/目錄下
這里是當(dāng)前的scor 指向 /storage/lawson/scores 中。這里顯示紅色,是因?yàn)?code>/storage/lawson/scores這個(gè)目錄不存在,如果創(chuàng)建該目錄,那就可以得到藍(lán)色的顯示了。
需要注意的是,當(dāng)前所有目錄下的文件都不能重名,因?yàn)槲抑坝幸粋€(gè)文件夾是scores,所以這里就簡(jiǎn)單的命名成了scor。
2.3 軟連接的刪除
rm -rf ./test_chk_ln/ 會(huì)刪除文件夾下的所有內(nèi)容,但是沒(méi)有刪除這個(gè)鏈接;
rm -rf ./test_chk_ln 則是僅刪除這個(gè)軟鏈接,不會(huì)刪除下面的內(nèi)容。
- 錯(cuò)誤示范
[root@server6 test_chk_ln]# cd ..
[root@server6 ~]# ll
總用量 84
-rw-------. 1 root root 1257 6月 16 01:17 anaconda-ks.cfg
drwxr-xr-x. 25 root root 4096 11月 1 10:28 azkabanJob
-rw-r--r--. 1 root root 67322 11月 4 10:24 azkabanJob.zip
drwxr-xr-x. 4 root root 37 7月 13 11:01 hadoop_temp
-rw-r--r--. 1 root root 54 7月 4 14:11 HelloLinux.txt
drwxr-xr-x. 2 root root 22 11月 4 10:41 test_chk
lrwxrwxrwx. 1 root root 9 11月 4 10:42 test_chk_ln -> test_chk/
-rw-r--r--. 1 root root 67 10月 8 15:52 zookeeper.out
[root@server6 ~]# rm -rf ./test_chk_ln/
[root@server6 ~]# ll
總用量 84
-rw-------. 1 root root 1257 6月 16 01:17 anaconda-ks.cfg
drwxr-xr-x. 25 root root 4096 11月 1 10:28 azkabanJob
-rw-r--r--. 1 root root 67322 11月 4 10:24 azkabanJob.zip
drwxr-xr-x. 4 root root 37 7月 13 11:01 hadoop_temp
-rw-r--r--. 1 root root 54 7月 4 14:11 HelloLinux.txt
drwxr-xr-x. 2 root root 6 11月 4 10:42 test_chk
lrwxrwxrwx. 1 root root 9 11月 4 10:42 test_chk_ln -> test_chk/
-rw-r--r--. 1 root root 67 10月 8 15:52 zookeeper.out
[root@server6 ~]# cd test_chk
[root@server6 test_chk]# ll
總用量 0
[root@server6 test_chk]# ll
總用量 0
可以發(fā)現(xiàn)該文件夾下的內(nèi)容都被刪了。。。
- 正確刪除軟連接
[root@server6 ~]# rm -rf ./test_chk_ln
[root@server6 ~]# ll
總用量 84
-rw-------. 1 root root 1257 6月 16 01:17 anaconda-ks.cfg
drwxr-xr-x. 25 root root 4096 11月 1 10:28 azkabanJob
-rw-r--r--. 1 root root 67322 11月 4 10:24 azkabanJob.zip
drwxr-xr-x. 4 root root 37 7月 13 11:01 hadoop_temp
-rw-r--r--. 1 root root 54 7月 4 14:11 HelloLinux.txt
drwxr-xr-x. 2 root root 22 11月 4 10:44 test_chk
-rw-r--r--. 1 root root 67 10月 8 15:52 zookeeper.out
[root@server6 ~]# cd test_chk/
[root@server6 test_chk]# ll
總用量 4
-rw-r--r--. 1 root root 12 11月 4 10:44 test.txt
參考文章
- https://www.cnblogs.com/cartsp/p/6437046.html
總結(jié)
以上是生活随笔為你收集整理的linux的软连接命令(文件夹建立软连接)(Linux.org)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: go语言下载及安装「建议收藏」(这12个
- 下一篇: Java之父:詹姆斯·高斯林 (Jame