简体   繁体   English

Linux - 如何将位于多个子目录中的相同扩展名的文件直接复制到一个子目录中?

[英]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.

相关问题 如何在多个子目录中找到具有相同扩展名的所有文件并使用 python 将它们移动到单独的文件夹中? - How can find all files of the same extension within multiple subdirectories and move them to a seperate folder using python? 如何在当前目录及其子目录中创建具有给定扩展名的文件列表? - How can I create a list of files in the current directory and its subdirectories with a given extension? 如何从子目录导入特定扩展名的所有文件并分别保存? - How can I import all files of a particular extension from subdirectories and save them separately? 如何比较两个不同文件夹中具有相同名称的两个.text文件的每一行? - How can I compare each line of two .text files with same name located in two different folder? 如何对齐和裁剪位于子目录中的图像以进行人脸识别? - How do I align and crop the images located in subdirectories for face recognition? 如何阻止 Python 混淆具有相同名称的子目录? - How can I stop Python mixing up subdirectories with the same name? 如何解析多个文本文件并将必需的输出附加到单个文件中。 (用于文档) - How to how can I parse several text files and get required output appended to a single file. (for Documentation) 如何解压缩相同子目录但不同文件夹中的文件 - How to unzip files in the same subdirectories but a different folder 我如何在Linux上下载没有扩展名的图像 - how can i download the images with no extension on linux 如何在一个目录中列出文件列表,其中该目录中的文件首先位于 python 中子目录中的文件之前? - How can I make a list of files in a directory where the files in that directory are first before files in subdirectories in python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM