How to check if a file is empty in Bash?

后端 未结 10 628
情书的邮戳
情书的邮戳 2020-11-30 18:41

I have a file called diff.txt. I Want to check whether it is empty.

I wrote a bash script something like below, but I couldn\'t get it work.

10条回答
  •  时光取名叫无心
    2020-11-30 19:06

    To check if file is empty or has only white spaces, you can use grep:

    if [[ -z $(grep '[^[:space:]]' $filename) ]] ; then
      echo "Empty file" 
      ...
    fi
    

提交回复
热议问题