【发布时间】: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页面中列出的所有选项,请说明当您确实使用那些处理符号链接的选项时会发生什么。