Optimizing a one-line find + exec command

2019-07-18 19:15发布

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条回答
做自己的国王
2楼-- · 2019-07-18 19:25

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.)

查看更多
登录 后发表回答