Rsync / Linux:阻止在目标目录中创建新目录

时间:2014-07-20 02:46:19

标签: linux terminal rsync mint

请原谅我的新手。

有关Rsync使用的问题。 例如,如果我指定此命令:

 rsync -av Downloads Downloads2

结果是目录" Downloads2"使用"下载"创建作为子目录,在/ Downloads2 / Downloads中是原始/下载目录的所有内容。

我想知道是否有一个选项会导致rsync将/ Downloads的内容复制到/ Downloads2而不创建/ Downloads2 / Downloads结构?

1 个答案:

答案 0 :(得分:2)

从“man rsync”可以看到,在源目录中添加一个尾部斜杠会阻止创建该目录:

          rsync -avz foo:src/bar/ /data/tmp

   A trailing slash on the source changes this behavior to avoid  creating
   an  additional  directory level at the destination.  You can think of a
   trailing / on a source as meaning "copy the contents of this directory"
   as  opposed  to  "copy  the  directory  by name", but in both cases the
   attributes of the containing directory are transferred to the  contain‐
   ing  directory on the destination.  In other words, each of the follow‐
   ing commands copies the files in the same way, including their  setting
   of the attributes of /dest/foo:

          rsync -av /src/foo /dest
          rsync -av /src/foo/ /dest/foo