1 Piping and redirection
1 in Linux Most of the commands are simple, rarely complex commands, each command is only a simple function, we can combine different commands to achieve complex functions
2 in Linux almost all of the commands returned by the data are plain text, and the majority of the data in plain text is entered in the form of a command
More than 3 command collaboration is done through pipelines and redirects.
The 4 command line Shell's data flow is defined as follows
Name Description number Defaults
stdin Standard Input 0 keyboard
STDOUT standard Output 1 terminal
STDERR standard error 2 terminal
5 command to receive parameters or data through stdin, outputting results or errors through stdout and stderr
2 redirect
1 > redirects the standard output to a file, which is overwritten if it is already there.
For example, we use the echo "haha" > output, which will output the output, and then in the echo "Linuxcast" > Output will overwrite
2 >> redirects the standard output to the file, which is appended to the back if the file is already there.
For example, we use echo "Tmplinuxcast" >> output, which appends output
3 2>, redirect standard error to file, if it does, it will overwrite
For example, we use LS-LD www.google.com 2> output, then we will print out the error
4 we can use 2>&1 to redirect standard output and standard errors to a file
5 We can use < to achieve the redirection standard input, but the use of relatively few
3 Pipeline |
1 grep command to find a file that contains keywords from a plain text file
Usage: grep keyword file
2 The standard output stdout as another command of the standard input stdin
Like the details of my home catalog output all the files, then we use the pipeline to grep the file containing the keyword from the output information
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/Linux/