【问题标题】:How to cp with symlinks pointing to new files copied? [closed]如何使用指向复制的新文件的符号链接进行 cp? [关闭]
【发布时间】:2022-01-23 11:46:31
【问题描述】:

假设我们在dir 下有一些文件,带有

$ cd dir && ls -lh
lrwxrwxrwx 1 root root  12 Mar 19  2021 target-symlink1 -> target-symlink2
lrwxrwxrwx 1 root root  20 Mar 19  2021 target-symlink2 -> target-realfile
-rw-r--r-- 1 root root  1G Mar 19  2021 target-realfile
lrwxrwxrwx 1 root root  1G Mar 19  2021 another-file

现在我们想将dir/target-*复制到new-dir/,我们希望看到的结果是

$ cd new-dir && ls -lh
lrwxrwxrwx 1 root root  12 Mar 19  2021 target-symlink1 -> target-symlink2
lrwxrwxrwx 1 root root  20 Mar 19  2021 target-symlink2 -> target-realfile
-rw-r--r-- 1 root root  1G Mar 19  2021 target-realfile

我们可以使用哪些 linux shell 命令来实现这一点,复制文件和符号链接并指向新复制的文件?

谢谢!

【问题讨论】:

  • 为了排除您已经尝试了man cp 页面中列出的所有选项,请说明当您确实使用那些处理符号链接的选项时会发生什么。

标签: bash shell symlink cp


【解决方案1】:

使用cp -a 尽可能保留。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-03-28
    • 2013-10-13
    • 1970-01-01
    • 2010-10-16
    • 1970-01-01
    • 1970-01-01
    • 2012-12-28
    相关资源
    最近更新 更多