In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
In this issue, the editor will bring you the relevant knowledge about "> / dev/null 2 > & 1" under Linux. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
"> / dev/null 2 > & 1" appears in some terminal commands or programs.
0: indicates keyboard input (stdin)
1: indicates standard output (stdout). The default is 1.
2: indicates error output (stderr)
Command > / dev/null 2 > & 1 & = = command 1 > / dev/null 2 > & 1 &
1) command: indicates a shell command or an executable program
2) >: indicates where to redirect
3) / dev/null: an empty device file that represents Linux
4) 2: indicates standard error output
5) & 1-means equivalent, 2 > & 1, indicating that the output redirection of 2 is equal to 1.
6) &: indicates background execution, that is, the instruction execution runs in the background
1 > / dev/null: indicates that standard output is redirected to an empty device file, that is, no information is output to the terminal and no information is displayed.
2 > & 1: indicates that the standard error output redirection is equivalent to the standard output, because the standard output has been redirected to the empty device file, so the standard error output is also redirected to the empty device file.
This command means to execute the program in the background, redirect error output 2 to standard output 1, and then put all standard output 1 into the / dev/null file, that is, empty.
So you can see that "> / dev/null 2 > & 1" is often used to avoid content output in the operation of shell commands or programs.
Ipaw O redirection
The purpose of redirection is to send the output of one command to another place.
For example, use the cat command to view a file, and the contents of the file are printed to the screen:
$cat foo.txtfoobarbaz
At this point, the screen is the standard output (standard output [stdout]) location of the command.
We can send the contents of the file somewhere else, for example, to redirect to the output.txt file:
$cat foo.txt > output.txt$ cat output.txtfoobarbaz
The first cat uses > to change the location of the stdout to another file.
Looking at another example, look at a file that does not exist:
$cat nop.txt > output.txtcat: nop.txt: No such file or directory
Why is the error message displayed on the screen instead of being sent to output.txt?
This involves another location: the standard error output standard error [stderr].
$cat nop.txt > output.txt
This command locates the stdout to the file without defining the location of the stderr, so the error message is displayed in the default location: the screen.
File descriptor
Everything in Linux is a file, each file has a file descriptor, and the value is a positive integer.
Therefore, the standard output stdout and the standard error output stderr also have their own file descriptors:
Stdout is 1
Stderr is 2
Synthesize $cat foo.txt > output.txt
In fact, it goes like this:
$cat foo.txt 1 > output.txt
It points stdout to output.txt, which is the abbreviation of 1 >.
So the output of the redirect error message should look like this:
$cat nop.txt 2 > error.txt$ cat error.txtcat: nop.txt: No such file or directory
A series of orders are:
$cat foo.txt > output.txt 2 > error.txt
Both the standard output stdout and the standard error output stderr are redirected.
Review the command at the beginning:
Ls foo > / dev/null 2 > & 1
Now it's basically understandable:
Stdout redirect to / dev/null
Stderr redirect to & 1
/ dev/null means empty device, redirect to empty device, that is, output information is not needed.
& 1 means that the value of file descriptor 1, that is, the value of standard output, then 2 > & 1 means that the standard error output, like standard output, is redirected to an empty device.
So what this command means is that both correct and error messages are not displayed.
The above is the relevant knowledge of "> / dev/null 2 > & 1" shared by the editor under Linux. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.