How to check if find command didn't find anything?

后端 未结 6 433
抹茶落季
抹茶落季 2021-01-01 14:11

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

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

but I want to use find comma

6条回答
  •  醉酒成梦
    2021-01-01 14:44

    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
    

提交回复
热议问题