Linux ">/dev/null 2>&1 &"

Source: Internet
Author: User

0: Indicates keyboard input (stdin)
1: Indicates standard output (stdout), system default is 1
2: Indicates error output (stderr)


Command >/dev/null 2>&1 & = = Command 1>/dev/null 2>&1 &


1) Command: Represents a shell command or an executable program
2);: indicates where to redirect
3)/dev/null: Empty device file representing Linux
4) 2: Indicates standard error output
5) &1:& denotes equivalent meaning, 2>&1, indicates 2 output redirect equals 1
6) &: Indicates background execution, that is, this instruction execution runs in the background

1>/dev/null: Indicates that standard output is redirected to an empty device file, which means no information is output to the terminal and no information is displayed.
2>&1: Indicates that the standard error output redirection is equivalent to standard output because the standard error output is also redirected to an empty provisioning document because the standard output was previously redirected to an empty device file
.


This command means to execute the program in the background and redirect the error output 2 to standard output 1, and then put the standard output 1 all into the/dev/null file, which is empty.
So you can see ">/dev/null 2>&1" commonly used to avoid shell commands or programs, such as the content output in the run.

What is the difference between command > file 2>file and command > File 2>&1?

Command > File 2>file means that the standard output information generated by the command is sent to file with the wrong output information. Command > File 2>file StdOut and stderr are sent directly to file, file will be opened two times, so stdout and stderr will cover each other, so write quite use FD1 and FD2 two simultaneously to seize the file of the pipeline.
and command >file 2>&1 This order will stdout directly sent to file, stderr inherit the FD1 pipeline, and then sent to file, at this time, file was opened only once, also only used a pipeline FD1, It includes the contents of stdout and stderr.
From IO efficiency, the efficiency of the previous command is less efficient than the following command, so when writing a shell script, we use command > file 2>&1.

2>&1 >/dev/null

Command-line redirection is ready before executing the command . The explanation sequence is left to right, 2&>1, and 1 is the screen, so the standard error redirects to the screen, and 1>/dev/null, the standard output redirects to/dev/null, the 2>&1 >/dev/null above is not The same time either produces standard output or produces a standard error. It's a two different thing.

To explain it in the following variable way, it is obvious that these two ways are different, the former is like:

A=1

B=a

And the latter is like:

B=a

A=1

&>/dev/null

This is, whatever you are. File descriptor, all redirected to/dev/null

http://blog.csdn.net/reyleon/article/details/11595985

http://blog.csdn.net/web256/article/details/8244286

http://blog.csdn.net/sunrier/article/details/7695839

Linux ">/dev/null 2>&1 &"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.