Lucas Vieites .com Logo
Lucas Vieites .com
«I intend all my puns»

Redirect error output to the same place as standard output

 

Example first:

cat file.txt > logfile.log 2>&1

This is because the shell (both Bourne and Korn) reads arguments from left to right (see UNIX Power Tools for more information).

The shell sees >file first and redirects stdout to file. Next 2>&1 sends fd2 (stderr) to the same place fd1 is going – that’s to the file. And that’s what you want.

Author:   ✦  Published:   ✦  Updated:   ✦