可以使用以下命令来判断文件是否为空:
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