zoukankan      html  css  js  c++  java
  • centos7建立删除软连接

    # 加软连接,注意源文件为绝对地址,不然移动软连接后,软连接就会失效
    ln -s 原文件绝对路径 软连接地址
    # 删除软连接
    
    rm -rf 软连接地址
    
    # 警告-警告-警告 注意这个“/”,如果软连接是目录,下面命令会删除【软连接目录下的所有文件】,而不是删除【软连接】
    
    rm -rf 软连接地址/

    ---------------------------------------------------------------------------------------------------

    先建立一个软连接

    [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)

  • 相关阅读:
    安卓笔记:Android 界面设计指南——人人都是产品经理就是个玩笑话
    Windows CMD 命令
    安卓开发:dex 文件反编译
    VBA 学习笔记 运算符
    工商管理同等学力申硕全国统一考试资料整理
    VBA 学习笔记 判断语句、循环
    VBA 学习笔记 日期时间函数
    安卓自动领水果福气
    【合集】人大商学院同等学力工商管理
    安卓笔记:进度设计原则和常见错误
  • 原文地址:https://www.cnblogs.com/soymilk2019/p/14876096.html
Copyright © 2011-2022 走看看