以一定深度的子文件夹递归rsync


17

我想rsync递归地创建一个文件夹,但只希望包含一定深度的子文件夹。

例如,我想要像这样的1,2,3或4个子文件夹的深度:

source/
├── subfolder 1
   ├── subsubfolder
      ├── subsubsubfolder
         └── wanted with depth 4.txt
      └── wanted with depth 3.txt
   └── wanted with depth 2.txt
├── subfolder 2
   └── wanted with depth 2.txt
└── wanted with depth 1.txt

Answers:


26

方便--exclude=选择。

同步到2深度(文件夹和子文件夹中的文件):

rsync -r --exclude="/*/*/" source/ target/

它会给你这个:

target/
├── subfolder 1
   └── wanted with depth 2.txt
├── subfolder 2
   └── wanted with depth 2.txt
└── wanted with depth 1.txt

同步至深度3(文件夹,子文件夹和子文件夹中的文件):

rsync -r --exclude="/*/*/*/" source/ target/

会给你:

target/
├── subfolder 1
   ├── subsubfolder
      └── wanted with depth 3.txt
   └── wanted with depth 2.txt
├── subfolder 2
   └── wanted with depth 2.txt
└── wanted with depth 1.txt
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.