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

后端 未结 6 431
抹茶落季
抹茶落季 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:36

    Exit 0 is easy with find, exit >0 is harder because that usually only happens with an error. However we can make it happen:

    if find -type f -exec false {} +
    then
      echo 'nothing found'
    else
      echo 'something found'
    fi
    

提交回复
热议问题