Linux standard output has no content

Linux standard input is file descriptor 0. It is the input of the command, the default is the keyboard, and it can also be the output of a file or other commands.

The linux standard output is file descriptor 1. It is the output of the command, the default is the screen, and it can also be a file.

The linux standard error is file descriptor 2. This is the error output of the command. The default is the screen, but it can also be a file.

The use of redirection has the following rules:

1) Standard input 0, output 1, and error 2 need to be redirected separately, and one redirection can only change one of them.

2) Standard input 0 and standard output 1 can be omitted. (when it appears to the left of the redirection symbol)

3) The file descriptor can be written directly when it is on the left side of the redirection symbol, and it is preceded by & when it is on the right side.

4) There can be no spaces between the file descriptor and the redirection symbol!

command < filename redirect standard input to the filename file

Command 0< filename redirects standard input to the filename file

command > filename redirects the standard output to the filename file (overwrite)

command 1> fielname redirect standard output to filename file (overwrite)

Command >> filename redirects the standard output to the filename file (append)

Command 1>> filename redirects the standard output to the filename file (append)

Command 2> filename redirects the standard error to the filename file (overwrite)

Command 2>> filename redirects the standard output to the filename file (append)

command > filename 2>&1 redirect standard output and standard error to filename file (overwrite)

command >> filename 2>&1 redirect standard output and standard error to filename file (append)

command < filename > filename2 redirect standard input to filename file, redirect standard output

                                                        into the filename2 file

command 0< filename 1> filename2 redirect standard input to filename file, redirect standard output

                                                        into the filename2 file

Here are some less common usages:

n<&- means to close the input number n

<&- means close standard input (keyboard)

n>&- means to turn off output number n

>&- means to close the standard output 

Guess you like

Origin blog.csdn.net/yetaodiao/article/details/131417316