bash 如何在不同的目录中找到相同扩展名的文件并将其复制到 linux 中的单个目录?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2815532/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How does one find and copy files of the same extension, in different directories, to a single directory in linux?
提问by Eli
So, How Do I find and copy all files,
那么,我如何查找和复制所有文件,
*.a
that are in,
在,
~/DIR{1,2,3,...}
to
到
~/tmp/foo?
回答by JustJeff
Assumed you meant recursively copy everything of type .a from some source location. Haven't verified yet, but this should do that.
假设您的意思是从某个源位置递归复制 .a 类型的所有内容。尚未验证,但这应该可以。
find <root-of-search> -type f -name '*.a' -exec cp {} /tmp/foo \;
replace with the top of wherever you want to search from. You might have to throw quotes around *.a, and you might have to replace escape the ending semicolon by putting it in single quotes rather than back-slashing it.
替换为您要搜索的任何位置的顶部。您可能必须在 *.a 周围加上引号,并且您可能必须通过将它放在单引号中而不是反斜线来替换转义结束分号。
回答by fmark
In a bash shell:
在 bash shell 中:
cp ~/DIR*/*.a ~/tmp/foo
回答by Alex Reynolds
find ~/DIR{1,2,...} -name *.a print0 | xargs -i -0 cp '{}' ~/tmp/foo

