How to copy symlinks to target as normal folders

92 linux symbolic-link command-line cp

i have a folder with symlinks:

marek@marek$ ls -al /usr/share/solr/
razem 36
drwxr-xr-x   5 root root  4096 2010-11-30 08:25 .
drwxr-xr-x 358 root root 12288 2010-11-26 12:25 ..
drwxr-xr-x   3 root root  4096 2010-11-24 14:29 admin
lrwxrwxrwx   1 root root    14 2010-11-24 14:29 conf -> /etc/solr/conf
Run Code Online (Sandbox Code Playgroud)

i want to copy it to ~/solrTest but i want to copy files from symlink as well

when i try to cp -r /usr/share/solr/ ~/solrTest

i will have symlink here:

marek@marek$ ls -al ~/solrTest
razem 36
drwxr-xr-x   5 root root  4096 2010-11-30 08:25 .
drwxr-xr-x 358 root root 12288 2010-11-26 12:25 ..
drwxr-xr-x   3 root root  4096 2010-11-24 14:29 admin
lrwxrwxrwx   1 root root    14 2010-11-24 14:29 conf -> /etc/solr/conf
Run Code Online (Sandbox Code Playgroud)

Fab*_*bio 118

cp -Lr /usr/share/solr/ ~/solrTest
Run Code Online (Sandbox Code Playgroud)

检查man页面是否有 unix 命令man cp

   -L, --dereference
          always follow symbolic links in SOURCE
Run Code Online (Sandbox Code Playgroud)

  • 我得到“cp:-H、-L 和 -P 选项可能未与 -r 选项一起指定。” (6认同)
  • @balupton:试试-LR (5认同)

小智 14

从手册页:

'-L' ,'--dereference' - 从符号链接复制时遵循符号链接。使用此选项,cp 无法创建符号链接。例如,源树中的符号链接(到常规文件)将被复制到目标树中的常规文件中。

所以这是您应该尝试的选项。


amp*_*ine 6

cp -r -L /usr/share/solr/ ~/solrTest
Run Code Online (Sandbox Code Playgroud)

cp(1)手册页:

  -L, --dereference
        always follow symbolic links in SOURCE
Run Code Online (Sandbox Code Playgroud)