Find files by size and copy them to other directory

安稳与你 提交于 2019-12-08 07:41:05

问题


I would like to find files with size less than 10Mb and copy them to a different folder. I have a unix command but it's not conserving folders, just copying files:

find . -size -10Mb -exec cp {} /Users/bernardo/Desktop/copia \;

回答1:


-exec cp -p --parents -t/Users/bernardo/Desktop/copia/ {} +

The key part is --parents, to mirror the directory structure. I used -p to preserve mode, timestamp, and ownership. I find -exec {} + more intuitive than -exec {} ;, but it doesn't matter here, beyond the need to reorder arguments to cp with the former.



来源:https://stackoverflow.com/questions/19820755/find-files-by-size-and-copy-them-to-other-directory

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!