日期:2014-05-16  浏览次数:20792 次

linux cp 命令的使用疑问
大家好,我有一堆文件,想快速复制。

我举个例子:

主文件夹为main,
其下面有folder1/folder11/folder111/x.txt
folder2/folder22/folder222/folder2222/y.txt

当然这些子文件夹中可能还有其他文件。

请问如何写cp命令,使之只复制*.txt文件,并且保持目录结构。
可能处在不同的文件夹中的txt文件可能有相同的文件名,也要保证给出警告。
------解决方案--------------------
zhblue@240x:~/tmp$ find
.
./target
./main
./main/folder2
./main/folder2/folder22
./main/folder2/folder22/y.txt
./main/folder1
./main/folder1/forlder11
./main/folder1/forlder11/x.txt
./main/folder3
zhblue@240x:~/tmp$ find main -name *.txt -exec cp --parents {} target \;
zhblue@240x:~/tmp$ find
.
./target
./target/main
./target/main/folder2
./target/main/folder2/folder22
./target/main/folder2/folder22/y.txt
./target/main/folder1
./target/main/folder1/forlder11
./target/main/folder1/forlder11/x.txt
./main
./main/folder2
./main/folder2/folder22
./main/folder2/folder22/y.txt
./main/folder1
./main/folder1/forlder11
./main/folder1/forlder11/x.txt
./main/folder3