可以使用以下命令來判斷文件是否為空:
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