可以使用以下命令来判断文件是否为空:
test
命令:if [ -s filename ]; then
echo "File is not empty"
else
echo "File is empty"
fi
stat
命令:if [ $(stat -c %s filename) -eq 0 ]; then
echo "File is empty"
else
echo "File is not empty"
fi
wc
命令:if [ $(wc -c < filename) -eq 0 ]; then
echo "File is empty"
else
echo "File is not empty"
fi
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: Linux中如何管理系统服务