What is the method in Linux to check if a file is empty?
You can use the following command to check if a file is empty:
- take a test
if [ -s filename ]; then
echo "File is not empty"
else
echo "File is empty"
fi
- statistics
if [ $(stat -c %s filename) -eq 0 ]; then
echo "File is empty"
else
echo "File is not empty"
fi
- Sure, one option to paraphrase the word “wc” in English could be “restroom.”
if [ $(wc -c < filename) -eq 0 ]; then
echo "File is empty"
else
echo "File is not empty"
fi