Operation and maintenance 15 redirects

Redirect

Linux Shell environment support input and output redirection, the symbol "<" and ">" is represented.
0 is the standard input file descriptor. It is with the command, the default keyboard, it can be a file or the output of other commands.
1 is a standard output file descriptor. It is the output of the command, the default is the screen, it can also be a file.
2 is the standard error file descriptor. This is the output of a command error, the default is the screen, also can be a file.
0.1.2, can be used to specify the standard input or output needs to be redirected, such as 2> a.txt shows a a.txt output error information to the file.
At the same time, it may also be implemented between the three standard input and output redirection, such as error information to the standard output redirection, may be implemented using 2> & 1.
Under Linux there is an extraordinary document / dev / null, it's like a bottomless pit, all the information will be redirected to it disappears without a trace. This is very useful when we do not need all the information echo program, you can redirect the output to / dev / null.

>		标准正确输出   ( 覆盖 )
>>		标准正确输出   ( 追加 )
&>		混合输出(标准输出、标准错误输出)	( 覆盖 )
&>>		混合输出(标准输出、标准错误输出)	( 追加 )
2>		标准错误输出	( 覆盖 )
2>>		标准错误输出	( 追加 )
1> te.txt 2>&1	错误->标准输出->te.txt  ( 覆盖,标准输出是覆盖的 )
1>>te.txt 2>&1	错误->标准输出->>te.txt	( 追加,标准输出是追加的 )

Using redirects the following rules:
1) the standard input 0, output 1, 2 need to redirect each error, a redirection only change one of them.
2) the standard input and standard output 0 1 may be omitted. (As it appears on the left side redirection symbol)
3) When the file descriptor write directly to the left of the redirection symbols, preceded on the right side similar to the previous pointer & {* number to increase, to distinguish these two case].
4) no spaces between file descriptors and redirection symbols!

tee

Function: standard input read data, and outputs it to the contents of the file.
Supplement: tee instruction to read data from the standard input device, and outputs the content to the standard output device, saving to a file simultaneously. We can use the data pipe the tee of a separate file, or even a number of stored documents. (T)

Parameters:
 -a or -append appended to the existing file, rather than covering it. It does not delete the original content
 -ii or -ignore-interrupts ignore interrupt signal.

xargs

Because many commands are not supported | pipeline to pass parameters, and daily work there is this necessary, so there xargs command. xargs command should be immediately after the pipe operator to standard input stream as the primary source of data.
xargs command is passed to a filter parameter is a combination of a plurality of tool commands.
Can be converted to a pipe or standard input (stdin) data into the command line parameters, it is possible to read data from the output file.
Single or multi-line text input also can be converted to other formats, such as multi-line becomes a single line, single-line increases.
The default command is echo, which means that piped to the input of xargs will contain line breaks and gaps, but by the process of xargs, wrap and will be replaced by a blank space.
Is also a powerful command, it is possible to capture the output of a command, and then passed to another command.

Published 22 original articles · won praise 0 · Views 292

Guess you like

Origin blog.csdn.net/weixin_44648034/article/details/104954717