Append both stdout and stderr to a file

> redirects stdout to a file, and overwrites the file.

&> redirects both stdout and stderr, and overwrites(?) the file.

I want append both stdout and stderr to a file, not overwrite. I tried &>> but it doesn't work. Does &> already do what I want? If not, any other trick?

5

1 Answer

There are (at least) two ways of achieving this:

  1. Either use this construct: cmd >>file.txt 2>&1 where >> file appends the output to the file and 2>&1 redirects the stderr to stdout.
  2. Or use cmd &>>file ensuring that you have bash version >4 (using bash --version) and #!/bin/bash at the beginning of file (#!/bin/sh won't work).

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like