[英]Linux - How can I copy files of the same extension located in several subdirectories into a single directly?
I have a folder which has many subdirectories, each with a *.nr
file in them. 我有一个包含许多子目录的文件夹,每个子目录中都包含一个*.nr
文件。 There are 1000 subdirectories, each containing at least one *.nr
file. 有1000个子目录,每个子目录至少包含一个*.nr
文件。 Is there a quick way to copy all those *.nr
files into a single directory? 有没有快速的方法将所有*.nr
文件复制到一个目录中?
I can write a quick python
script to iterate through the files, but this seems like overkill if there is a quick command line based way to do it. 我可以编写一个快速的python
脚本来遍历文件,但如果有一个基于命令行的快速方法,这似乎有些过分。
I've been googling, but I'm not sure what exact terms I should be googling. 我一直在谷歌搜索,但我不确定我应该谷歌搜索的具体条款。
Thanks! 谢谢!
就像是
find /path/to/src -name "*.nr" -exec cp \{\} /path/to/dest \;
If you're on a system with GNU cp
, this will do it faster: 如果您使用的是GNU cp
系统,这样可以更快地完成:
find /path/to/src -name "*.nr" -print0 | xargs -0 cp -t /path/to/dest
Copying all .c
files under my src
dir: 复制我的src
目录下的所有.c
文件:
time find ~/src -name "*.c" -exec cp \{\} ~/src/Cfound/ \;
. . .
real 0m1.838s
user 0m9.530s
sys 0m1.110s
time find . -name "*.c" -print0 | xargs -0 cp -t ./Cfound/
. . .
real 0m0.057s
user 0m0.010s
sys 0m0.060s
bash中最简单的方法:
for F in */*.nr; do cp $F otherdir/ ; done
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.