Tee -a does not recreate file

rmtee

I am running the following command on a Raspberry Pi 3 Debian latest release:

cat /dev/ttyUSB0 | tee -a /media/pi/KINGSTON/klima.out | grep -F $ | tee -a /media/pi/KINGSTON/log

The command works fine and does what it should; however, when I delete (manually or by CRON) the klima.out file, it is not re-created. The command keeps running, the log file continues to be appended, but the klima.out file doesn't come back. (also no buffering). I want to delete it once a week for not letting it grow over all boundaries.
Any suggestions?

Best Answer

If you want to recover the file blocks, you need to blank the file, not unlink it:

This portable way should work with most shells :

: > /media/pi/KINGSTON/klima.out

Unlinking the file (i.e. rm) is removing the directory entry but doesn't affect the file contents (inode) as long as the file is kept open by readers or writers.

Related Question