In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the meaning of nohup / dev/null 2 > & 1 in linux. It is very detailed and has a certain reference value. Interested friends must read it!
Nohup command: if you are running a process and you don't think it will end when you exit your account, you can use the nohup command. This command can continue to run the corresponding process after you exit your account / close the terminal. Nohup means not to hang (n ohang up).
The general form of the command is: nohup command &
Ls xxx 1 > out.txt 2 > & 1nohup / mnt/Nand3/H2000G > / dev/null 2 > & 1 &
For & 1, it is more accurate to say that it is a file descriptor 1, and 1 generally represents STDOUT_FILENO, which is actually a dup2 (2) call. He standard output to all_result, and then copy standard output to file descriptor 2 (STDERR_FILENO). As a result, file descriptors 1 and 2 point to the same file table entry, or the wrong output is merged. Where 0 for keyboard input 1 for screen output 2 for error output. Redirect standard errors to standard output and throw them under / DEV/NULL. In popular terms, it is to throw all standard output and standard errors into the dustbin.
Command > out.file 2 > & 1 &
Command > out.file redirects the output of command to the out.file file, that is, the output is not printed to the screen, but to the out.file file. 2 > & 1 redirects the standard error to the standard output, where the standard output has been redirected to the out.file file, that is, the standard error is also output to the out.file file. The last & is to let the command be executed in the background.
Imagine what 2 > 1 stands for, 2 and > represent error redirection, and 1 represents error redirection to a file 1, not standard output
Replace it with 2 > & 1 & combining with 1 represents standard output and becomes an error redirection to standard output.
You can use it.
Ls 2 > 1 test will not report an error without 2 files, but will output an empty file 1
Ls xxx 2 > 1 test, no xxx this file error output to 1
Ls xxx 2 > & 1 test, will not generate 1 this file, but the error went to standard output
Ls xxx > out.txt 2 > & 1, which can actually be replaced with ls xxx 1 > out.txt 2 > & 1; the redirect symbol > defaults to 1, and the error and output are sent to out.txt.
Why should 2 > & 1 be written at the end?
Command > file 2 > & 1
First, command > file redirects standard output to file. 2 > & 1 is the act of standard error copying standard output, that is, it is also redirected to file, and the end result is that both standard output and error are redirected to file.
Command 2 > & 1 > file
2 > & 1 standard error copies the behavior of standard output, but at this time the standard output is still on the terminal. The output is redirected to file after file, but the standard error remains on the terminal.
With strace, you can see:
1. Command > file 2 > & 1
The key system call sequence to achieve redirection in this command is:
Open (file) = = 3 dup2 (3je 1) dup2 (1m 2)
2. Command 2 > & 1 > file
The key system call sequence to achieve redirection in this command is:
Dup2 (1) open (file) = = 3 dup2 (3)
Why use / dev/null 2 > & 1 to write. This command means that all standard output and error output are redirected to / dev/null, that is, all generated information is discarded. Let me tell you what's the difference between command > file 2 > file and command > file 2 > & 1.
First of all, ~ command > file 2 > file means to send the standard output information and error output information generated by the command to file. Command > file 2 > file, stdout and stderr are sent directly to file, and file will be opened twice, so that stdout and stderr will overwrite each other, which is equivalent to using both FD1 and FD2 to seize file pipes at the same time.
The command command > file 2 > & 1 sends stdout directly to file. After stderr inherits the FD1 pipeline, it is sent to file. At this time, file is opened only once, and only one pipeline FD1 is used, which includes the contents of stdout and stderr.
In terms of IO efficiency, the former command is less efficient than the latter command, so when writing shell scripts, we often use command > file 2 > & 1.
The above is all the content of the article "nohup / dev/null 2 > & 1 in linux". Thank you for reading! Hope to share the content to help you, more related knowledge, 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.