优化单行find + exec命令 [英] Optimizing a one-line find + exec command

查看:193
本文介绍了优化单行find + exec命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要获取系统上大约1M个文件的文件信息(名称,大小,修改日期)。
我目前使用的命令是:
$ b $ pre $ sudo查找$ FULFILLMENT$ ARCH1$ ARCH2 $ MASTERING-type f -exec ls -lT {} +

有没有办法改进这个?唯一的要求是我必须得到上述卷中的所有文件,并为每个文件,拉取名称,大小和date_modified。



(有没有办法做一个stat命令在这里,而不是?这会加快速度?)

这需要大约一个光纤连接的机器一小时。

find 来打印出 ls

$ p $ sudo find ... -type f -printf'%p%s $ c $'$内置打印:

t \\\
'

我不确定会有多快,但它会节省分支到 ls ,并且节省了必须再次查询磁盘以通过 ls 来检索信息 find 已经有了,所以它应该至少



在这种方式下,您可以在 -printf 中搜索 man find 以获得更多关于这些格式的信息字符串,特别是可以自定义上次修改时间的表示,并且可以为其他字段指定显式字段宽度。)

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.

解决方案

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

这篇关于优化单行find + exec命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆