【问题标题】:How to copy a directory with symbolic links and resolve them?如何复制带有符号链接的目录并解决它们?
【发布时间】:2014-05-18 21:11:09
【问题描述】:

我想递归地复制一个目录的内容,该目录包含符号链接(符号链接)以及带有 Bash / Shell 脚本的普通文件。我不知道如何复制符号链接内容。伪代码看起来像这样:

for file in directory do
  if is symlink
    resolve symlink and copy its contents
  else 
    copy the file / folder

我的目录结构如下所示:

base/
  dir1/
  symlinkdir1*/ (--> ../somewhere/else/dirA)
    /file1
    /file2
  symlinkdir2*/ (--> ../somewhere/else/dirB)
    /file3
    /file4
  …

在复制过程之后,我想要一个这样的目录结构:

base/
  dir1/
  symlinkdir1/ (no symlink, actual directory)
    /file1
    /file2
  symlinkdir2/ (no symlink, actual directory)
    /file3
    /file4
  …

【问题讨论】:

    标签: bash shell terminal copy symlink


    【解决方案1】:

    cp -rL /source /destination

    r = 递归 L = 跟随和扩展符号链接

    【讨论】:

    • 在 MacOS 上需要大写 -R
    • 使用L和不使用L有什么区别?其他两个答案不使用它,我想知道有什么区别
    • -L 将用真实文件替换符号链接。这就是为什么我的答案是正确的,而另一个是错误的。
    【解决方案2】:

    只需使用带有-r 选项的cp 命令递归复制。完全不需要脚本,

    【讨论】:

      【解决方案3】:

      只是cp -r ./SourceFolder ./DestFolder

      【讨论】:

      • 不。这没有用。目的地仍然包含符号链接。
      猜你喜欢
      • 2021-12-30
      • 1970-01-01
      • 2012-12-24
      • 1970-01-01
      • 2010-11-17
      • 1970-01-01
      • 2023-03-14
      • 2015-07-11
      • 1970-01-01
      相关资源
      最近更新 更多