如何检查find命令是否未找到任何内容? [英] How to check if find command didn't find anything?

查看:290
本文介绍了如何检查find命令是否未找到任何内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道可以通过这样的find命令使用for循环

I know that is possible to use for loop with find command like that

for i in `find $something`; do (...) done

但是我想将find命令与"if"一起使用.

but I want to use find command with "if".

我正在尝试通过脚本创建有关已删除文件的进度注释(并稍后记录日志文件).我需要检查

I am trying to create progress comments (and log files later) about removed files by my script. I need to check if

find /directory/whatever -name '*.tar.gz' -mtime +$DAYS

有没有发现.如果不是,我想说回声您没有文件早于$ DAYS天"或类似的内容;)

found something or not. If not I want to say echo 'You don't have files older than $DAYS days' or something like this ;)

如何在shell脚本中做到这一点?

How I can do that in shell script?

推荐答案

计算输出的行数并将其存储在变量中,然后对其进行测试:

Count the number of lines output and store it in a variable, then test it:

lines=$(find ... | wc -l)
if [ $lines -eq 0 ]; then
...
fi

这篇关于如何检查find命令是否未找到任何内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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