The command behavior of Linux we provide a pipeline and redirection mechanism that enables multi-command collaboration through pipelines and redirects.
The data flow of the command-line shell is defined in the following three ways:
Name |
Description |
Number |
Default |
Stdin |
Standard input |
0 |
Keyboard |
STDOUT |
Standard output |
1 |
Terminal |
STDERR |
Standard error |
2 |
Terminal |
command to receive parameters or data via stdin, through stdout output or through stderr output errors, through pipeline and redirection to control the data flow of the CLI
If the output is redirected to/dev/null there will be no output (this is usually used to filter the error message in the results)
Redirect:
> redirect stdout to file (overwrite), example: echo "xxx" > outfile
>> redirect stdout to file (append), example: echo "xxx" >> outfile
2> redirect stderr to file (overwrite), example: LS nothere 2> errout
2>&1 combining stderr with stdout, example: LS nothere 2>&1 alloutput
< redirect stdin, example: grep xxx </etc/passwd
Pipeline:
| (A vertical bar): The stdout of one command (the previous command) as the stdin of another command (the latter command), example: Ls-l | grep xxx
Pipelines are often used to combine different commands to implement a complex function that redirects an output or error message that is typically used to hold a command, which can be used to record execution results or to save an error message to a specified file.
linux-(16) Piping and redirection