rsync仅复制特定子文件夹中的特定文件,而不创建空文件夹(rsync copy only specific files from specific subfolders, without creating empty folders)
想象一下像这样的文件结构:
test ├── a │ ├── 0 │ │ ├── file0.rtf │ │ ├── file0.txt │ │ ├── file1.rtf │ │ ├── file1.txt │ │ ├── file2.rtf │ │ └── file2.txt │ ├── 1 │ │ ├── file0.rtf │ │ ├── file0.txt │ │ ├── file1.rtf │ │ ├── file1.txt │ │ ├── file2.rtf │ │ └── file2.txt │ ├── 2 │ │ ├── file0.rtf │ │ ├── file0.txt │ │ ├── file1.rtf │ │ ├── file1.txt │ │ ├── file2.rtf │ │ └── file2.txt │ └── 3 │ ├── file0.rtf │ ├── file0.txt │ ├── file1.rtf │ ├── file1.txt │ ├── file2.rtf │ └── file2.txt └── b ├── 0 │ ├── file0.rtf │ ├── file0.txt │ ├── file1.rtf │ ├── file1.txt │ ├── file2.rtf │ └── file2.txt ├── 1 │ ├── file0.rtf │ ├── file0.txt │ ├── file1.rtf │ ├── file1.txt │ ├── file2.rtf │ └── file2.txt ├── 2 │ ├── file0.rtf │ ├── file0.txt │ ├── file1.rtf │ ├── file1.txt │ ├── file2.rtf │ └── file2.txt └── 3 ├── file0.rtf ├── file0.txt ├── file1.rtf ├── file1.txt ├── file2.rtf └── file2.txt我不知道 a和b的真实姓名。 不过,如果它们在子文件夹0 ,我想从a和b子文件夹中复制所有*.txt文件(但是它们被命名)。
如果我使用它会有用
rsync -avz --include=*/ --include='*/0/*.txt' --exclude=* test/ test2/但是,rsync创建空文件夹1 ,我想避免。 我该怎么做呢?
上面rsync命令的输出:
sending incremental file list a/ a/0/ a/0/file0.txt a/0/file1.txt a/0/file2.txt a/1/ a/2/ a/3/ b/ b/0/ b/0/file0.txt b/0/file1.txt b/0/file2.txt b/1/ b/2/ b/3/我想要
sending incremental file list a/ a/0/ a/0/file0.txt a/0/file1.txt a/0/file2.txt b/ b/0/ b/0/file0.txt b/0/file1.txt b/0/file2.txtImagine a file structure like this:
test ├── a │ ├── 0 │ │ ├── file0.rtf │ │ ├── file0.txt │ │ ├── file1.rtf │ │ ├── file1.txt │ │ ├── file2.rtf │ │ └── file2.txt │ ├── 1 │ │ ├── file0.rtf │ │ ├── file0.txt │ │ ├── file1.rtf │ │ ├── file1.txt │ │ ├── file2.rtf │ │ └── file2.txt │ ├── 2 │ │ ├── file0.rtf │ │ ├── file0.txt │ │ ├── file1.rtf │ │ ├── file1.txt │ │ ├── file2.rtf │ │ └── file2.txt │ └── 3 │ ├── file0.rtf │ ├── file0.txt │ ├── file1.rtf │ ├── file1.txt │ ├── file2.rtf │ └── file2.txt └── b ├── 0 │ ├── file0.rtf │ ├── file0.txt │ ├── file1.rtf │ ├── file1.txt │ ├── file2.rtf │ └── file2.txt ├── 1 │ ├── file0.rtf │ ├── file0.txt │ ├── file1.rtf │ ├── file1.txt │ ├── file2.rtf │ └── file2.txt ├── 2 │ ├── file0.rtf │ ├── file0.txt │ ├── file1.rtf │ ├── file1.txt │ ├── file2.rtf │ └── file2.txt └── 3 ├── file0.rtf ├── file0.txt ├── file1.rtf ├── file1.txt ├── file2.rtf └── file2.txtWhere I do not know the real names of a and b. Nevertheless, I want to copy all *.txt files from subfolders of a and b (however they are named) if they are in the subfolder 0.
It kind of works if I am using
rsync -avz --include=*/ --include='*/0/*.txt' --exclude=* test/ test2/However, rsync creates empty folders 1, 2, 3, which I would like to avoid. How do I do this?
Output from the rsync command above:
sending incremental file list a/ a/0/ a/0/file0.txt a/0/file1.txt a/0/file2.txt a/1/ a/2/ a/3/ b/ b/0/ b/0/file0.txt b/0/file1.txt b/0/file2.txt b/1/ b/2/ b/3/I want
sending incremental file list a/ a/0/ a/0/file0.txt a/0/file1.txt a/0/file2.txt b/ b/0/ b/0/file0.txt b/0/file1.txt b/0/file2.txt最满意答案
事实证明答案很简单。 只需添加--prune-empty-dirs标志即可。
rsync -avz --include=*/ --include='*/0/*.txt' --exclude=* --prune-empty-dirs test1/ test2/这就是我想要的。
It turns out the answer is simple. Just adding the --prune-empty-dirs flag does the trick.
rsync -avz --include=*/ --include='*/0/*.txt' --exclude=* --prune-empty-dirs test1/ test2/That is what I wanted.
更多推荐
发布评论