When you redirect the output of a command to a file using >, and that process takes a while (like apt-get update) will the file being written to be opened and closed only once for the entire process duration, or is it opened and closed multiple times (closed when there is no output)?


It's only opened once, by the shell process that interprets the "> filename" before it starts the command. Since that shell process is waiting for the command to exit, there is nobody to close the file, until command exits.

Output will seem to appear, in bursts, in the file, as disk buffering and caching does its magic.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.