Linux判断文件是否为空,不为空则打印该文件的大小,使用到的命令是-s + filename

-s filename
如果文件大小大于0,则返回true。

例如:

查看当前目录

# ls -l
total 8
-rwxrwxr-x 1 pentester pentester 136 6月  19 15:58 is_Empyt.sh
-rw-r--r-- 1 root      root        7 6月  19 15:59 myfile.txt

查看脚步内容:

# cat is_Empyt.sh 

#! /bin/bash

if [ -s ./myfile.txt ] ; then 
  echo 'ths file is not empyt and file info:'
  du -sh myfile.txt  #打印文件大小
else
  echo 'empty!'
fi

执行效果:

# ./is_Empyt.sh 
ths file is not empyt and file info:
4.0K    myfile.txt

 

相关文章:

  • 2022-01-01
  • 2021-12-04
  • 2021-11-27
  • 2021-11-28
  • 2021-11-28
  • 2021-07-04
  • 2021-06-11
  • 2021-09-23
猜你喜欢
  • 2021-05-17
  • 2022-12-23
  • 2022-12-23
  • 2021-10-29
  • 2022-12-23
  • 2021-09-06
  • 2022-12-23
相关资源
相似解决方案