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