This question already has an answer here:
I wanted to
tail the last 100 lines of a file to the same file, but the command
tail -n 100 file > file doesn't work, I assume because the stdout gets written to the file 'live', before everything was read from the original file.
Is there some way to pipe the output to something, that then keeps it until all 100 lines are there, and then outputs it to the file? Or just another way to shorten the file in this way?