In my Python script I needed a fast/efficient way to set a max filesize on a file I'm constantly writing to. Rather than bring the whole thing into py's RAM, I ran this shell command:
sed -i '1d' file.csv
I monitor the filesize periodically and run the command as needed. Problem is that now if I tail -f file.csv
, tail stops tailing the file as soon as sed removes a line from it. Any solution?
The basic problem is
sed
creates a new file. This is shown by the extract below:There isn't, as far as I know, an easy way to truncate the start of a file.
I'd suggest getting your python application to listen on a unix/tcp socket, and once accepted put that stream into the logging framework and then use
nc ... | tail
to watch output.Michael Hampton suggests the obvious
tail -F
, but I personally mostly useless
nowadays:There being no shorthand alternative to
--follow-name
, I have to use an alias: