簡體   English   中英

Linux cp 命令保存文件結構

[英]Linux cp command to preserve file strucutre

所以我有一個像這樣的linux文件結構:

/base/dir_a/a/this_d=1_another/testfile
/base/dir_a/a/this_d=2_another/testfile
/base/dir_a/a/aa/this_d=1_another/testfile
/base/dir_a/a/ab/this_d=1_another/testfile
/base/dir_a/a/ab/this_d=2_another/testfile

我想將包含d=1所有文件夾復制到dir_b

/base/dir_a/*d=1* -> /base/dir_b

所以最終的dir_b應該是:

/base/dir_a/a/this_d=1_another/testfile
/base/dir_a/a/aa/this_d=1_another/testfile
/base/dir_a/a/ab/this_d=1_another/testfile

我嘗試了如下副本(2個命令..)

cp /base/dir_a/a/*/*d=1* -> /base/dir_b;
cp /base/dir_a/a/*d=1* -> /base/dir_b;

但這將嘗試僅將this_d=1_another文件夾復制到/base/dir_b ,這會導致問題,因為我所有的嵌套文件夾都具有相同的名稱。

我該如何解決這個問題?

如果您可以使用 rsync,則最容易使用:

rsync -avP --include=*/ --include=**/*d=1* --exclude='*' /base/dir_a /base/dir_b

但是,這會產生一堆空目錄作為副作用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM