It's well known that redirecting standard output and error to the same file with cmd >out_err.txt 2>out_err.txt can lead to loss of data, as per the example below:
work:/tmp$ touch file.txt work:/tmp$ ls another_file.txt ls: cannot access 'another_file.txt': No such file or directory The above is the setup code for the example. An empty file file.txt exists and another_file.txt is not a thing. In the code below, I naively redirect to out_err.txt both input and output os listing these files.
work:/tmp$ ls file.txt another_file.txt >out_err.txt 2>out_err.txt work:/tmp$ cat out_err.txt file.txt t access 'another_file.txt': No such file or directory And we see that we lost a few characters in the error stream. However, using >> works in the sense that replicating the example would yield keep the whole output and the whole error.
Why and how does cmd >>out_err.txt 2>>out_err.txt work?
cmd >>out_err.txt 2>>out_err.txtwork?" – Somewhat related: Is redirection with>>equivalent to>when target file doesn't yet exist?