Hi,
I have a TEST.dat file. As a clean up process, I have to delete the TEST.dat file if it is empty. Basically, I don't want to delete TEST.dat if it contains anything in it but want to delete TEST.dat if it contains any spaces or nothing in it.
Is there a command to check if the file is empty then delete it.
Will appreciate any advice in this regards.
Thanks
follow these steps
1> check for spaces using sed remove all the spaces
2> use an if condition to check the size of the file like
if [[ ! -s txt ]] then
echo " empty "
else
echo "non empty"
fi
3) now delete in if statement
rm -f txt.
-Manish Jha
This sh/ksh test should work:
if [ ! -s TEST.dat ] ; then rm TEST.dat ; fi
There is also a -size 0 expression to find(1) but that's probably more than you need right now.