If we redirect a command such as sar -r 1> a_file.txt
how does this works with opening, writing the output of the command and closing the file?
In other words, how does redirecting a command output works in the background opening writing and closing the file? (specially a command such as the above that periodically and continually sends data to output)
I am wondering if there is some cacheing involved and if some flushing (writing the contents to the file) occurs at the end
( sleep 5; echo 1; sleep 5; echo 2; ) > testfile
and in a second terminaltail -f testfile