我想要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
答案1
方便--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