file
by the directives >file
and
>>file
.
For example, the shell command
./hello > out.txtdeletes the contents of the file
out.txt
and then
sends the standard output of the program hello
into that
file. Alternatively, the shell command
./hello >> out.txtappends the file
out.txt
with whatever hello
prints to standard output.
This two redirections are actually an abbreviation of the full commands
1>file
and 1>>file
where 1 is
the default number of the stdout stream.
file
by the directives 2>file
and 2>>file
. For example, the following command
redirects standard output into out.txt
and standard error
into errors.txt
.
./prog 1> out.txt 2> errors.txt
&>file
redirects both stdout and
stdin into file
.
2>&1
redirects stderr to stdout.
<
, for example the
shell command
./prog < input.txtconnects the standard input stream of the program
prog
with the file file
such that all reads from the standard
input actually read from the attached file.
|
, connects the standard output of one program
to the standard input of another program, for example,
echo 1.23 | ./progsends the string "1.23" into the standard input of the program
./prog
.