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
最后
以上就是心灵美金毛最近收集整理的关于Linux判断文件是否为空,不为空则打印该文件的大小的全部内容,更多相关Linux判断文件是否为空,不为空则打印该文件内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复