back
input output error: bash
Each program in linux is connected to three "files" (everything's a
file in unix:-). These are called:
- Standard input (STDIN)
- Standard output (STDOUT)
- Standard error (STDERR)
By default, standard input comes from the terminal window (usually
from the keyboard, really). Standard output and standard error go to
the terminal window
Any or all of these can be connected to real files instead. Here
are some recipes to do just that.
Redirecting output
- > redirects standard output to a file e.g.
du
>
/tmp/disk_usage
- 1> Same as above.
- 2> redirects standard error to a file e.g.
./my_buggy_program &>
/tmp/file_including_error_messages
- &> redirects both stdin and stout to the same file
e.g. ./my_buggy_program &>
/tmp/file_with_both_outputs
- Using an extra > as in program_file >>
data_file appends to an existing file (creating if first if it
doesn't exist) rather than overwriting any existing data.