Optimizing a one-line find + exec command

巧了我就是萌 提交于 2019-12-24 02:45:14

问题


I need to get the file information (name, size, date modified) of about 1M+ files on a system. The command I am currently using is:

sudo find "$FULFILLMENT" "$ARCH1" "$ARCH2" "$MASTERING" -type f -exec ls -lT {} +

Is there a way to improve this? The only requirement is I must get all the files in the above volumes and for each file, pull the name, size, and date_modified.

(Is there a way to do a stat command here instead? Would that speed things up?)

This takes about an hour on a fiber connected machine.


回答1:


Instead of farming the printing out to ls, you can use find's built-in printing:

sudo find ... -type f -printf '%p      %s      %t\n'

I'm not sure how much faster that'll be, but it saves the forking out to ls, and it saves having to consult the disk a second time to retrieve information via ls that find already has anyway, so it should be at least somewhat faster.

(By the way, you can search man find for -printf for more information on those format strings. In particular, you can customize the presentation of the last-modified-time, and you can specify explicit field-widths for the other fields.)



来源:https://stackoverflow.com/questions/14595013/optimizing-a-one-line-find-exec-command

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