This is not a "how to append and not overwrite" question. I'm not looking for a file that combines the output of two commands. It's just a mistake I made and I would like to understand why the system did what it did
I use a command (on a remote ssh command line) that takes a long time to complete and outputs data (line by line every few seconds) to stdout so I redirect it to a file:
command > file.out &
Sometimes the remote session disconnects but the command keeps on running in the background. I didn't know this so I run the same command again, before the first one had finished:
command > file.out &
When both processes have finished I would expect to have (after reading some answers at this site) a single file with the lines from both commands messed up, but the output file only has the output from one of the 2 executions.
Why doesn't the file have both outputs intertwined (as warned in the comments here)? Which one of the 2 outputs does the final file belong to?
EDIT:
Removed one of the questions (why is the output file not locked for writing?) as it's explained here