Linux 命令之软连接详解
2023-09-14 09:13:15 时间
前言
- 文章来源:CSDN@LawsonAbs
1.软连接
1.1 创建语法
ln -s target source
解释下:
ln -s
:表示创建一个软连接;
target
:表示目标文件(夹)【即被指向的文件(夹)】
source
:表示当前目录的软连接名。
1.2 具体示例
- step 1.创建测试文件及文件夹
[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 创建软连接时,不用创建文件夹。
2.2 命令示例解释
执行的命令是: ln -s /storage/lawson/scores scor
其含义就是:将scor指向 /storage/lawson/scores/目录下
这里是当前的scor 指向 /storage/lawson/scores 中。这里显示红色,是因为/storage/lawson/scores
这个目录不存在,如果创建该目录,那就可以得到蓝色的显示了。
需要注意的是,当前所有目录下的文件都不能重名,因为我之前有一个文件夹是scores
,所以这里就简单的命名成了scor
。
2.3 软连接的删除
rm -rf ./test_chk_ln/
会删除文件夹下的所有内容,但是没有删除这个链接;
rm -rf ./test_chk_ln
则是仅删除这个软链接,不会删除下面的内容。
- 错误示范
[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
可以发现该文件夹下的内容都被删了。。。
- 正确删除软连接
[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
相关文章
- 重启MySQL:Linux指令简解(linux重启mysql命令)
- Linux学习入门到精通:百度云盘免费汇总教程(linux教程百度云盘)
- Linux无密码SSH安全连接的极致体验(linux无密码ssh)
- Linux命令行清理缓存的技巧(linux清理缓存的命令)
- Linux系统如何安全退出(linux系统退出命令)
- Linux批处理命令的精彩之旅(linux命令batch)
- Linux进程内存管理之分配学习(linux进程内存分配)
- 海康威视开源Linux系统,建设智慧世界(海康linux)
- Linux 命令:管理更高级权限(linux命令权限)
- TC命令在Linux系统中的应用(tc命令linux)
- 的方法Linux进入SSH的简单步骤(linux进入ssh)
- Linux快速入门:一步步掌握Linux系统(linux快速入门教程)
- Linux 中按日期排序文件的方法(linux文件日期排序)
- Linux服务管理:简单的命令操作(linux服务管理命令)
- 设备Linux绑定Mac设备:实现跨平台无缝连接(linux绑定mac)
- Linux下关闭端口的简单指令(linux关闭端口的命令)
- Linux无线命令大全:25个实用无线设置命令!(linux无线命令)
- Linux命令:比较数字大小的方法(linux比较数字大小)
- 世界连接未来:Linux开启全新世界(linux-连接)
- 备份Linux文件完整备份:保障数据安全(linux文件完整)
- 指令Linux a 命令:解锁Linux技术之路(linux-a)
- 实现无缝连接:Linux远程桌面Windows,保持高效办公(linux远程桌面windows)
- 轻松搞定扫描任务:Linux下的必备扫描工具推荐(linux下扫描工具)
- 学习Linux必备:掌握更高效的文件查看方法——使用Linux命令more(linux命令more)
- 查看Linux下端口占用情况分析(查看端口占用 linux)
- 深入浅出Linux 节点名,一起开启计算之旅(linux 节点名)
- Linux文件夹软连接实现快速导航(linux文件夹软连接)