My script uses a tmp file where it writes and deletes data. I use redirections to write, and
sed to delete.
At some moment, I want to check if the file exists and is empty, but my code fails (the file exists and has no data):
[[ -s /tmp/tmp_file ]] && echo "not empty" || echo "empty" not empty
When I check the file size, it shows 1 byte, despite that the file has no data in it.
If I open the file with gedit and save the file, then it shows 0 byte size.
Why is this happening?
How to be sure that, deleting contents, no extra byte is left?
Added outputs of
ls -ld and
od, when the file is "empty" (one byte):
ls -ld tmp_file -rwxr-xr-x 1 root root 1 dic 18 15:43 tmp_file od tmp_file 0000000 000012 0000001
Image showing the one byte size:
Image of the file opened in gedit: