+ -
当前位置:首页 → 问答吧 → 批量打印文件最后修改时间出错,救命啊,在线等!

批量打印文件最后修改时间出错,救命啊,在线等!

时间:2011-07-17

来源:互联网

find /home/racing_all/ \( -path /home/racing_all/template -type d -o -path /home/racing_all/jcnews  -type d \) -prune -o -type f  -name '*.htm' -o -name '*.cfm' |xargs stat -t |awk '{print  $1  $13 }'  > /home/time.txt


报错误stat: invalid option -- i
Try `stat --help' for more information.
stat: invalid option -- j
Try `stat --help' for more information.
stat: invalid option -- i
Try `stat --help' for more information.
stat: invalid option -- m
Try `stat --help' for more information.
stat: invalid option -- 2
Try `stat --help' for more information.

time.txt里面少了几万跳数据
需求:需要得到文件路径和最后修改时间存放在time.txt里面,
类似:
/home/racing_all/static_page/horse9_static/54/5433.htm1309508384
/home/racing_all/static_page/horse9_static/54/5404.htm1309508384
/home/racing_all/static_page/horse9_static/54/5444.htm1309508384
/home/racing_all/static_page/horse9_static/54/5430.htm1309508384
/home/racing_all/static_page/horse9_static/54/5476.htm1309508384
/home/racing_all/static_page/horse9_static/54/5488.htm1309508384
/home/racing_all/static_page/horse9_static/54/5495.htm1309508384
/home/racing_all/static_page/horse9_static/54/5485.htm1309508384
/home/racing_all/static_page/horse9_static/54/5484.htm1309508384
/home/racing_all/static_page/horse9_static/54/5461.htm1309508384
/home/racing_all/static_page/horse9_static/54/5497.htm1309508384
/home/racing_all/static_page/horse9_static/54/5422.htm1309508384
/home/racing_all/static_page/horse9_static/54/543.htm1309508384
/home/racing_all/static_page/horse9_static/54/5452.htm1309508384
/home/racing_all/static_page/horse9_static/54/5483.htm1309508384
/home/racing_all/static_page/horse9_static/54/5462.htm1309508384
/home/racing_all/static_page/horse9_static/54/5412.htm1309508384
/home/racing_all/static_page/horse9_static/54/5428.htm1309508384
/home/racing_all/static_page/horse9_static/54/5411.htm1309508384

最后跟的是文件最后修改时间,但是数据我的shell数据不完整,少了几万条,大侠救命啊!

作者: sickcat2004   发布时间: 2011-07-17

回复 sickcat2004


    find {你的代码} -print0  |xargs -0 stat -t |awk '{print $1,$13}' # -0 数字零

作者: yinyuemi   发布时间: 2011-07-17



QUOTE:
回复  sickcat2004


    find {你的代码} -print0  |xargs -0 stat -t |awk '{print $1,$13}' # -0 数 ...
yinyuemi 发表于 2011-07-17 15:46




    大侠 没有报错了,但是数据只有几千条啊,find 到的数据是有5万多跳的!,请指教啊!

作者: sickcat2004   发布时间: 2011-07-17



QUOTE:
回复  sickcat2004


    find {你的代码} -print0  |xargs -0 stat -t |awk '{print $1,$13}' # -0 数 ...
yinyuemi 发表于 2011-07-17 15:46




    find /home/racing_all/ \( -path /home/racing_all/template -type d -o -path /home/racing_all/jcnews  -type d \) -prune -o -type f  -name '*.htm' -o -name '*.cfm' |wc -l
有5万多条呢
51259

find /home/racing_all/ \( -path /home/racing_all/template -type d -o -path /home/racing_all/jcnews  -type d \) -prune -o -type f  -name '*.htm' -o -name '*.cfm'  -print0 |xargs -0 stat -t |wc -l
只有9985条了
9985

作者: sickcat2004   发布时间: 2011-07-17

回复 sickcat2004


    这个原因不大清楚,另外,关于stat 加awk部分可以用下面的代替,避免文件名中有空格时,awk代码部分的结果会出错
stat -c "%n %Z"

作者: yinyuemi   发布时间: 2011-07-17



QUOTE:
回复  sickcat2004


    这个原因不大清楚,另外,关于stat 加awk部分可以用下面的代替,避免文件名中 ...
yinyuemi 发表于 2011-07-17 16:14




看来只能先把文件路径写到硬盘,再用shell循环遍历文件内容来产生文件最后修改时间了。。。555

作者: sickcat2004   发布时间: 2011-07-17

热门下载

更多