I'm writing continuously to a file, and I want to tail it from another shell. But it seems that as long as the file is open for writing,
tail -f filename can't show all the new lines until the file is closed again.
Unfortunately, opening and closing the file many times a second slows my script down to the point where data is received faster than it can be written, so I can't close the file during the process.
The writing is being done by a python program:
ser = serial.Serial('/dev/ttyACM2',9600) f = open("filename", "a+") while True: s = ser.readline() f.write(s + "\r\n") Isn't there a way to view the contents of a file that is in the process of being written to?
tail -f <file>? Or better:tail -F <file>, the uppercase F will follow even if the file does not exist yet or is logrotated etc.tail -fon the file, or of the program writing to the file doing buffering (either explicitly or, more likely, implicitly). How are you writing to the file? Buffering of output is done for performance reasons, but the data would not be written until the buffer is full. Sometimes buffering can be avoided.