BASH Shell: How To Redirect stderr To stdout ( redirect stderr to a File )
Q. How do I redirect stderr to stdout? How do I redirect stderr to a file?
A. Bash and other modern shell provides I/O redirection facility. There are 3 default standard files (standard streams) open:
[a] stdin - Use to get input (keyboard) i.e. data going into a program.
[b] stdout - Use to write information (screen)
[c] stderr - Use to write error message (screen)
Understanding I/O streams numbers
The Unix / Linux standard I/O streams with numbers:
| Handle | Name | Description |
| 0 | stdin | Standard input |
| 1 | stdout | Standard output |
| 2 | stderr | Standard error |
Redirecting the standard error stream to a file
The following will redirect program error message to a file called error.log:
$ program-name 2> error.log
$ command1 2> error.log
Redirecting the standard error (stderr) and stdout to file
Use the following syntax:
$ command-name &>file
OR
$ command > file-name 2>&1
Another useful example:
# find /usr/home -name .profile 2>&1 | more
Redirect stderr to stdout
Use the command as follows:
$ command-name 2>&1
Subscribe to our free e-mail newsletter or RSS feed to get all updates.
You can Email this page to a friend.
Related Other Helpful FAQs:
- How do I save or redirect stdout and stderr into different files?
- Restrict Linux users to their home directories only
- Where Does The PHP Error Log Reside
Leave a Reply
We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!
Tags: error message, I/O redirection, keyboard, Linux, log program, program error, redirect stderr stdout to file, redirect stderr to file, redirect stdout to file, redirection, standard error, stderr, stdin, stdout, streams, syntax, UNIX



Recent Comments
Today ~ 32 Comments
Yesterday ~ 1 Comment
Yesterday ~ 3 Comments
Yesterday ~ 2 Comments
Yesterday ~ 3 Comments