如何复制包含符号链接的整个目录?

时间:2013-01-10 02:52:06

标签: directory copy symlink freebsd cp

我想将/home/private_html/userx/中的完整目录内容复制到/home/private_html/usery/,问题是目录userx包含很少的符号链接,并且在使用cp时只是跳过它们(跳过发生,如果符号链接指向file,如果它指向目录,它只是复制整个目录...)。

我使用的命令如下:

# cp -iprv /home/private_html/userx/ /home/private_html/usery/

有没有人可以将目录“原样”复制到其他地方?

2 个答案:

答案 0 :(得分:0)

在FreeBSD上,cp没有-r选项。它确实有-R,它可以做你想要的:

 -R    If source_file designates a directory, cp copies the directory and
       the entire subtree connected at that point.  If the source_file
       ends in a /, the contents of the directory are copied rather than
       the directory itself.  This option also causes symbolic links to be
       copied, rather than indirected through, and for cp to create spe‐
       cial files rather than copying them as normal files.  Created
       directories have the same mode as the corresponding source direc‐
       tory, unmodified by the process' umask.

答案 1 :(得分:0)

罗兰对-R旗帜是正确的。您还可以使用一对tar进程,这将使您的命令更加独立于系统:

tar -C /home/private_html/userx/ -cpf - . | tar -C /home/private_html/usery/ -epf -