> 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?
1 Answer
There are (at least) two ways of achieving this:
- Either use this construct:
cmd >>file.txt 2>&1where>> fileappends the output to the file and2>&1redirects thestderrtostdout. - Or use
cmd &>>fileensuring that you have bash version >4 (usingbash --version) and#!/bin/bashat the beginning of file (#!/bin/shwon't work).