[英]Copy bulk files to another destination using a given prefix in bash
我想將所有比另一個新的文件從其原始位置/lib/
復制到另一個目標/dest/lib/
要識別這些文件,我只需使用:
$ cd /lib/
$ find . -newer foobar
./foo/bar.py
./bar/foo/bar/foo.py
...
不幸的是,我不能簡單地使用此命令,因為cp
不知道如何動態創建文件夾。
因此,我使用了以下命令:
find /foo -type f -newer foobar | \
xargs -n1 -I% sh -c 'mkdir -vp `dirname /dest/%` && cp -v % /dest/%'
這看起來非常復雜,而且速度非常慢。 有更好的解決方案嗎?
您可以為此使用tar
,例如,讓我們擁有目錄“ 1”,然后將某些內容復制到目錄“ 2”,然后:
cd 1
tar -c a.txt 3/b.txt | tar -x -C ../2
您也可以使用rsync
它與本地路徑一起使用
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.