简体   繁体   English

Linux CLI查找和cp问题

[英]Linux CLI find and cp issues

Im trying to find a set number of files in a directory and then copy them to another directory using the find and cp command. 我试图在目录中查找一定数量的文件,然后使用find和cp命令将它们复制到另一个目录。

this is the command i have so far: 这是我到目前为止的命令:

find /usr/share -name a* -type f -group admin -size -10240c | cp /usr/share/ ./thecopy/

Now it finds the files but does not copy the files to the location I'm trying to send them but finds the files in question. 现在,它找到了文件,但没有将文件复制到我要发送的位置,而是找到了有问题的文件。 Any suggestions please? 有什么建议吗?

Try something like: 尝试类似:

find /usr/share -name a* -type f -group admin -size -10240c | cp {} ./thecopy/ \;

{} is the placeholder for the files that match your criteria {}是符合您条件的文件的占位符

If you want to retain the directory structure you can try something like: 如果要保留目录结构,可以尝试如下操作:

find /usr/share -name a* -type f -group admin -size -10240c | rsync -av {} ./thecopy/ \;
find /usr/share -name a* -type f -group admin -size -10240c -exec cp {} ./thecopy/\;

That won't recreate any directory structure under thecopy. 这不会在该副本下重新创建任何目录结构。 But will copy the files it finds to your directory needed 但是会将找到的文件复制到所需的目录中

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM