停止更新,敏捷测试及TestOps解决体系,关注订阅号TestOps

Linux下简单的判断目录中是否有新文件的Shell

上一篇 / 下一篇  2011-12-30 12:04:46 / 个人分类:自动化测试

在做dailybuild的时候经常需要判断是不是有新版本出现,所以就写了这样一个shell
该shell脚本可以帮助你判断当前目录下是否有新文件出现,旧文件信息保存在oldfiles.log内。

no/HfIe zU!H0
if [ -f oldfiles.log ]
then
        newfile=` ls -t | head -1 `
        cat oldfiles.log | grep $newfile >/dev/null
        if [ $? -eq 1 ]
        then
                echo "there is a new file: $newfile"
                echo $newfile >> oldfiles.log
        else
                echo "there is no new files"
        fi
51Testing软件测试网h J%r:k)e n \7{*qO%b
else
ls -t -r > oldfiles.log
echo "cache old files info"
fi

ca$Y1h3d.]Qg&}h1l/x0
51Testing软件测试网X[/rb Va|N

TAG:

云层专版 引用 删除 云层   /   2012-01-06 17:41:02
貌似可以改成这样写
grep $newfile oldfiles.log >/dev/null
云层专版 引用 删除 云层   /   2012-01-06 17:37:13
有何更好的写法?
原帖由sataerman于2012-01-04 12:50:39发表
cat oldfiles.log | grep $newfile >/dev/null

干嘛要两个进程用管道,这个性能很烂啊
Yes We Can 引用 删除 sataerman   /   2012-01-04 12:50:39
cat oldfiles.log | grep $newfile >/dev/null

干嘛要两个进程用管道,这个性能很烂啊
 

评分:0

我来说两句

Open Toolbar