首页 > 其他 > 详细

centos7建立删除软连接

时间:2021-06-12 01:15:47      阅读:19      评论:0      收藏:0      [点我收藏+]

先建立一个软连接

[root@rekfan.com  test ] # ls -il
总计  0
1491138 -rw-r–r– 1 root root 48 07-14 14:17 file1
1491139 -rw-r–r– 2  root root 0 07-14 14:17 file2
1491139 -rw-r–r– 2 root root 0 07-14 14:17  file2hand
#建立file1和file1soft软连接
[root@rekfan.com  test ] # ln -s file1  file1soft
[root@rekfan.com  test ] # ls -il
总计 0
1491138 -rw-r–r– 1 root  root 48 07-14 14:17 file1
1491140 lrwxrwxrwx 1 root root 5 07-14 14:24  file1soft -> file1
1491139 -rw-r–r– 2 root root 0 07-14 14:17  file2
1491139 -rw-r–r– 2 root root 0 07-14 14:17 file2hand

删除上面建立的软连接

[root@rekfan.com  test ] # ls -il
总计  0
1491138 -rw-r–r– 1 root root 0 07-14 14:17 file1
1491140 lrwxrwxrwx 1  root root 5 07-14 14:24 file1soft -> file1
1491139 -rw-r–r– 2 root root 0  07-14 14:17 file2
1491139 -rw-r–r– 2 root root 0 07-14 14:17  file2hand
#删除软连接
[root@rekfan.com  test ] # rm -rf file1soft
[root@rekfan.com  test ] #  ls -il
总计 0
1491138 -rw-r–r– 1 root root 0 07-14 14:17 file1
1491139  -rw-r–r– 2 root root 0 07-14 14:17 file2
1491139 -rw-r–r– 2 root root 0 07-14  14:17 file2hand



删除软链接 确实是用rm 但是!!!
rm -fr xxxx/ 加了个/ 这个是删除文件夹
rm -fr xxxx 没有/ 这个是删除软链接

 注意

源文件最好是绝对路径,这样移动软链接就不会报错

需要注意的是:   源文件的路径 是根据 软链接 的路径来计算的,而不是根据当前路径来计算的

 

创建软连接,是非常简单的,直接使用ln -s 命令即可,其语法为:ln -s 原始文件路径 软链接文件路径。

比如, ln -s a.txt a_soft. 给a.txt创建了链接文件a_soft。

       但是,如果当前所在目录为/home. 要给该目录下的a.txt文件创建一个软连接a_soft,放在其子目录B下,首先想到的是这样:

       ln -s ./a.txt ./B/a_soft

       结果很不幸,这是错误的,创建出来的a_soft文件时找不到a.txt文件的。为什么呢??

       这是因为,ln -s创建链接文件,如果原始文件路径时相对路径,其相对路径的基准路径为链接文件的路径(这么理解,是通过链接文件找到源文件,因此就是以链接文件的路径为当前路径了)。因此,上面的链接文件路径为B目录,而源文件则认为是B目录下的文件,因此当然错误了!

       解决办法

      (1)源文件使用绝对路径:    ln -s /home/a.txt ./B/a_soft

      (2)源文件使用相对路径: ln -s ../a.txt ./B/a_soft  (B目录的上一级目录是home目录,目录下存在a.txt)

centos7建立删除软连接

原文:https://www.cnblogs.com/soymilk2019/p/14876096.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!