如何检查 find 命令是否没有找到任何东西? [英] How to check if find command didn't find anything?
本文介绍了如何检查 find 命令是否没有找到任何东西?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道可以将 for 循环与类似的 find 命令一起使用
I know that is possible to use for loop with find command like that
for i in `find $something`; do (...) done
但我想使用带有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屋!
查看全文