【问题标题】:creating soft links with the same name as the target file创建与目标文件同名的软链接
【发布时间】:2014-03-05 15:32:08
【问题描述】:
ln -s /dir1/file1   /dir2/file1

我想在目标 dir1 中创建一个与 dir2 中的源文件名相同的软链接 如何在目标路径中不输入 file1 名称的情况下完成此操作

【问题讨论】:

    标签: shell awk filenames symlink hardlink


    【解决方案1】:

    如果您要创建多个符号链接,一遍又一遍地输入名称会非常令人沮丧。这是我绕过在 Linux 中重新输入名称的方法。

    这是我的示例文件结构:

    source/
     - file1.txt
     - file2.js
     - file3.js
    target/
    
    


    为单个文件创建符号链接

    ~$ ln -sr source/file2.js target/

    结果:

    source/
     - file1.txt
     - file2.js
     - file3.js
    target/
     - file2.js
    


    为source 中具有匹配扩展名的所有文件创建符号链接

    ~$ ln -sr source/*.js target/

    结果:

    source/
     - file1.txt
     - file2.js
     - file3.js
    target/
     - file2.js
     - file3.js
    


    为source中的所有文件创建符号链接

    ~$ ln -sr source/* target/

    结果:

    source/
     - file1.txt
     - file2.js
     - file3.js
    target/
     - file1.txt
     - file2.js
     - file3.js
    




    相对论

    注意r 选项。如果您不包含-r,则必须输入相对于链接位置的链接源。

    • ~$ ln -s ../source/file1.txt target/ 工作
    • ~/target$ ln -s ../source/file1.txt . 工作
    • ~$ ln -s source/file1.txt target/ 不起作用

    另见:

    How to create symbolic links to all files (class of files) in a directory?

    Linux man pages

    【讨论】:

      【解决方案2】:

      您可以使用 ln-only 选项来做到这一点:

      ln -s -t /dir1 /dir2/file1
      

      【讨论】:

      • 所以我想我也可以做到这一点ls -s -t /d1 /d2/*tyvm
      • 我最终使用了这个cp -rs /dir/<search pattern> /dest1
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-06-29
      • 2011-06-19
      • 1970-01-01
      • 1970-01-01
      • 2011-02-06
      • 1970-01-01
      • 2012-06-25
      相关资源
      最近更新 更多