免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1707 | 回复: 2
打印 上一主题 下一主题

find 找不到文件的时候就写入log文件 如何设置? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-01-12 13:02 |只看该作者 |倒序浏览
find命令无论是否找到文件 返回的状态都是0,这可以从$?看出来。
但是locate处理上是有区别的。

---------------------------------------

[oraclebi@cnbisrv shell]$ find -type l
[oraclebi@cnbisrv shell]$ echo $?
0
[oraclebi@cnbisrv shell]$ find -type d
.
./subdir
./subdir/subdir
[oraclebi@cnbisrv shell]$ echo $?
0

---------------------------------------

[oraclebi@cnbisrv shell]$ locate test_test
/home/oraclebi/shell/test_test
[oraclebi@cnbisrv shell]$ echo $?
0
[oraclebi@cnbisrv shell]$ locate test_testdfd
[oraclebi@cnbisrv shell]$ echo $?
1
[oraclebi@cnbisrv shell]$

现在有个需求,就是使用find命令,查不到文件就写信息进入log日志,但是我这样使用实现不了:

[oraclebi@cnbisrv shell]$ grep "abc" /dev/null $(find -type l || echo "mylog content" > ./mylog.log)
[oraclebi@cnbisrv shell]$ cat mylog.log
cat: mylog.log: No such file or directory

但同样,使用locate就可以这样处理。

[oraclebi@cnbisrv shell]$ grep "abc" /dev/null $(locate test.testdfd || echo "mylog content" > ./mylog.log)
[oraclebi@cnbisrv shell]$ cat mylog.log
mylog content
[oraclebi@cnbisrv shell]$

请问,如果我还是想用find实现这样的功能,该如何操作呢???

谢谢。

论坛徽章:
0
2 [报告]
发表于 2012-01-12 13:51 |只看该作者
求助啊~

论坛徽章:
1
巳蛇
日期:2013-10-28 15:55:33
3 [报告]
发表于 2012-02-09 18:28 |只看该作者
回复 1# zhoudaoyu


    如果find的结果为空, 说明没有找到东西^_^.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP