Redirection Forms
|
File descriptor |
Name |
Common abbreviation |
Typical default |
|
0 |
Standard input |
stdin |
Keyboard |
|
1 |
Standard output |
stdout |
Screen |
|
2 |
Standard error |
stderr |
Screen |
The usual input source or output destination can be changed with the redirection commands listed in the following sections.
Simple redirection
|
Command |
Action |
|
|
Send output of cmd to file (overwrite). |
|
|
Same as preceding, even if
|
|
|
Send output of cmd to file (append). |
|
|
Same as preceding, even if
|
|
|
Take input for cmd from file. |
|
|
Read standard input up to a line identical to text (text can be stored in a shell variable). Input usually is typed at the keyboard or in the shell program. Commands that typically use this syntax include cat, echo, ex, and sed. If text is quoted (using any of the shell’s quoting mechanisms), the input is passed through verbatim. Otherwise, the shell performs variable and command substitutions on the input. When quoting text, the ending delimiter must be quoted identically. |
Multiple redirection
|
Command |
Action |
|
|
Send both standard output and standard error to file. |
|
|
Same as preceding, even if
|
|
|
Append standard output and standard error to end of file. |
|
|
Same as preceding, even if
|
|
|
Pipe standard error together with standard output. |
|
|
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access