In Ubuntu can root overwrite any file?
Solution 1:
sudo
only applies to the command run; your append >>
occurs as the current user.
Solution 2:
Best solution: run "sudo program|sudo tee -a output_file >/dev/null"
tee writes to file and stdout, >/dev/null redirects the output to /dev/null (just discards it) and the -a option tells tee to append to the file (as >> does) instead of overwriting the file (as > does).
run a simple command with sudo first, so the password gets cached, because otherwise you get two password-prompts on the same line and need to answer both before being able to continue.