简体   繁体   English

按名称查找文件夹然后复制文件

[英]Find folder by name then copy files

I need to find subdirectories called "child" and copy the files in those folders to a new directory. 我需要找到名为“child”的子目录,并将这些文件夹中的文件复制到新目录中。 Can't get it to work. 无法让它发挥作用。

I can get as far as finding the subdirectories but I can't copy the files from them. 我可以找到子目录,但我不能从他们复制文件。

> find /Volumes/COMMON-LIC-PHOTO-1/STUDIO-COMPLETE/ISSUETRAK/2016/03_2016 -type d -iname child

The above will find all subdirectories in 03_2016 named "child" but how do I now copy the files inside those directories? 以上将找到03_2016中名为“child”的所有子目录,但我现在如何复制这些目录中的文件?

I tried this but the problem is that it seems to want to copy the directories themselves and not just the files: 我试过这个,但问题是它似乎想要复制目录本身,而不仅仅是文件:

> find /Volumes/COMMON-LIC-PHOTO-1/STUDIO-COMPLETE/ISSUETRAK/2016/03_2016 -type d -iname child | xargs cp '{}' /Volumes/COMMON-LIC-PHOTO-1/STUDIO-COMPLETE/ISSUETRAK/TEST \;

I can't get it to target only the files. 我不能让它只针对文件。

You're close: 你很亲密:

> find $YOUR_PATH/03_2016/ -type d -iname child | xargs -I {} find -type f {} | xargs -I {} cp {} /Volumes/COMMON-LIC-PHOTO-1/STUDIO-COMPLETE/ISSUETRAK/TEST

Note: You might overwrite files that share the same name at the final destination 注意:您可能会覆盖在最终目标位置具有相同名称的文件

This might be a little cleaner than the above answer: 这可能比上面的答案更清晰:

find $(find /Volumes/COMMON-LIC-PHOTO-1/STUDIO-COMPLETE/ISSUETRAK/2016/03_2016 -type d -iname child | xargs) -type f -exec cp {} /Volumes/COMMON-LIC-PHOTO-1/STUDIO-COMPLETE/ISSUETRAK/TEST \;

Two calls to find, one call to xargs. 两次调用找到,一次调用xargs。 Like the other answer, this also will overwrite duplicate file names. 与其他答案一样,这也会覆盖重复的文件名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 复制文件夹结构和仅文件名 - Copy folder structure and only files name 如何查找某些文件并将其复制到文件夹中? - How to find certain files and copy them in a folder? 使用查找将文件复制到新文件夹 - Use find to copy files to a new folder 在目录中查找文件副本到新文件名 - Find files in a directory copy to a new file name 从Linux中包含文件夹名称的多个文件夹复制文件 - Copy files from multiple folders with including folder name in Linux 用于将文件夹名称复制并添加到来自多个子目录的文件的 Shell 脚本 - Shell script to copy and prepend folder name to files from multiple subdirectories 复制/移动不同文件夹中同名的多个文件 - copy/move same name multiple files in different folder Bash:查找包含特定字符串的文件并将它们复制到文件夹中 - Bash: Find files containing a certain string and copy them into a folder 将文件夹中的所有文件复制到另一个以 . 到文件名并将其重命名回原始文件名 - Copy all files in folder to another folder prepending a . to the file name and rename it back to original file name 仅在下面的目录中查找和同名文件,然后复制到其他目录 - Find and files of same name only in directory below and copy to a different directory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM