求助文本处理问题

dirk_xqgogopp
求助文本处理问题

要监控目录下当天产生的文件名:
1.用命令ls -l |grep "`date +'%b %d'`"获得如下内容:
-rw-r--r--   1 toptea   bosswg            0 Jun 19 14:06 bbb
-rw-r--r--   1 toptea   bosswg            0 Jun 19 14:06 ccc
-rw-r--r--   1 toptea   bosswg            0 Jun 19 14:06 eee
-rw-r--r--   1 toptea   bosswg            0 Jun 19 14:06 fff
-rw-r--r--   1 toptea   bosswg           25 Jun 19 15:21 fffff.txt
-rw-r--r--   1 toptea   bosswg           18 Jun 19 15:16 hhhh.txt
-rw-r--r--   1 toptea   bosswg          724 Jun 19 16:42 qx_test.err
-rw-r--r--   1 toptea   bosswg          101 Jun 19 17:00 qx_test.pl
现在想获取最后一列 新产生的文件名 怎么搞呢

flw
有现成的 find 命令你不用。
man find

liaosnet
回复 #1 dirk_xqgogopp 的帖子

最新产生的?
ls -alt | awk 'NR==2{print $NF}'

walkerxk
find查找当天的文件就行了,如果一定要按照上面处理的话
sed 's/.* //'
希望你的文件名里面没有空格。

dirk_xqgogopp
回复 #3 liaosnet 的帖子

是当天产生的 不是最新产生的

寂寞烈火
[quote]原帖由 [i]dirk_xqgogopp[/i] 于 2008-6-20 08:41 发表 [url=http://bbs.chinaunix.net/redirect.php?goto=findpost&pid=8624107&ptid=1164879][img]http://bbs.chinaunix.net/images/common/back.gif[/img][/url]
是当天产生的 不是最新产生的 [/quote]
try:
find . -type f -daystart -mtime 0

chzht001
回复 #6 寂寞烈火 的帖子

效果不错,[img]http://bbs.chinaunix.net/images/smilies/icon_razz.gif[/img]

ruifox
[quote]原帖由 [i]flw[/i] 于 2008-6-19 17:38 发表 [url=http://bbs.chinaunix.net/redirect.php?goto=findpost&pid=8622174&ptid=1164879][img]http://bbs.chinaunix.net/images/common/back.gif[/img][/url]
有现成的 find 命令你不用。
man find [/quote]


find恐怕确实不行,find只能查找24小时之内创建的文件。还只能用ls -l |grep "`date +'%b %d'`"这样的方式!

ruifox
[quote]原帖由 [i]寂寞烈火[/i] 于 2008-6-20 09:40 发表 [url=http://bbs.chinaunix.net/redirect.php?goto=findpost&pid=8624614&ptid=1164879][img]http://bbs.chinaunix.net/images/common/back.gif[/img][/url]

try:
find . -type f -daystart -mtime 0 [/quote]

每次看到这些无法使用的命令,就很郁闷。。。

walkerxk
无法使用?环境?UNIX?

寂寞烈火
[quote]原帖由 [i]ruifox[/i] 于 2008-6-20 10:40 发表 [url=http://bbs.chinaunix.net/redirect.php?goto=findpost&pid=8625342&ptid=1164879][img]http://bbs.chinaunix.net/images/common/back.gif[/img][/url]



find恐怕确实不行,find只能查找24小时之内创建的文件。还只能用ls -l |grep "`date +'%b %d'`"这样的方式! [/quote]
*NIX没有"创建文件"这个概念~~ , 而且, find非常强大

ly5066113
[quote]原帖由 [i]ruifox[/i] 于 2008-6-20 10:40 发表 [url=http://bbs.chinaunix.net/redirect.php?goto=findpost&pid=8625342&ptid=1164879][img]http://bbs.chinaunix.net/images/common/back.gif[/img][/url]



find恐怕确实不行,find只能查找24小时之内创建的文件。还只能用ls -l |grep "`date +'%b %d'`"这样的方式! [/quote]

touch -t $(date +%Y%m%d0000.00) tmp

find . -newer tmp

ruifox
[quote]原帖由 [i]ly5066113[/i] 于 2008-6-20 11:41 发表 [url=http://bbs.chinaunix.net/redirect.php?goto=findpost&pid=8626111&ptid=1164879][img]http://bbs.chinaunix.net/images/common/back.gif[/img][/url]


touch -t $(date +%Y%m%d0000.00) tmp

find . -newer tmp [/quote]

这个好!适合SCO UNIX!

walkerxk
果然是unix,怪不得不能用。ly的创意不错。