Append Error To File

We can append the errors of a program to a file by using the 2>> operator.

Run Error Producing Code To See Error

pwd -thiswillproduceerror
-bash: pwd: -t: invalid option
pwd: usage: pwd [-LP]

Create File

touch errors.txt

Append The Standard Error To File

Note that we run pwd -thiswillproduceerror three times, each time appending the results to errors.txt.

pwd -thiswillproduceerror 2>> errors.txt; pwd -thiswillproduceerror 2>> errors.txt; pwd -thiswillproduceerror 2>> errors.txt

View File’s Contents To See Redirected Standard Output

cat errors.txt
-bash: pwd: -t: invalid option
pwd: usage: pwd [-LP]
-bash: pwd: -t: invalid option
pwd: usage: pwd [-LP]
-bash: pwd: -t: invalid option
pwd: usage: pwd [-LP]