Notation: | stdin | standard input | (keyboard) |
stdout | standard output | (screen) | |
stderr | standard error | (screen) |
Character(s) | shell | Redirects |
---|---|---|
< | Bourne, C | stdin |
> | Bourne, C | stdout |
>> | Bourne, C | append stdout |
<<str | C (B) | read input lines until str is encountered at the beginning of a line |
>& (2>&1) | C (B) | stdout and stderr |
>2 | B | stderr |
>>& | C | append stdout and stderr |
>! | C | stdout (overrides noclobber) |
>&! | C | stdout and stderr (overrides noclobber) |
>>! | C | append stdout (overrides noclobber) |
>>&! | C | append stdout and stderr (overrides noclobber) |
So - for example - the line
$ (find / -name "*pattern*" -print > /dev/tty) >& /dev/null
displays files that match pattern on the screen (even the terminal is represented by a file: /dev/tty) and sends error messages to /dev/null (that means: throws them away).
$ cmd_1 | cmd_2 > out_file
In this example the command cmd_1 has no input from a file (but it may have input from the terminal) and sends its output to cmd_2, which uses it instead of terminal input. cmd_2 sends its output to the file out_file.
The following example shows how to get a listing of the subdirectories only:
$ ls -l | grep "^d"