Linux background operation & symbols, nohup commands, output redirection and other usage methods

Source: Internet
Author: User

a number of scenarios are listed to facilitate understanding of these commands and parameters:

Add the & symbol at the end of the command to allow the process to execute in the background so that it returns immediately to the prompt, and we can do the following. such as: Command &

But at this point, if the process has output, it will still show up, which will interfere with our shell window. So consider redirecting the standard output to a file, such as: Command >output &

Now it's clean . But sometimes we find that the process running in the background is wrong, and we want to save the error message as well. That's it. Two variables are defined by default in Linux: 1 refers to standard output, and 2 refers to error output, so it is written like this: Command 1>output 2>error &, normal output in the outputs file, incorrect output in the error file. This is also the same as command >output 2>error &

sometimes just want to keep one, the other is neither output nor save, then use this device/dev/null, so ignore error output: Command 1>output 2>/dev/null & ignore Standard output: Command 1 >/dev/null 2>error &; Ignore All output: command 1>/dev/null 2>/dev/null

1, 22 kinds of information can also be redirected, so this: command 1>output 2>&1 & indicates that the error output is also redirected back to standard output, that is, both of the information is saved to output. Then why not write command 1>output 2>output &? The answer is no, do not look at the output to/dev/null can, but if you write the same file name can cause a conflict, so if you want to keep only the above wording; similarly: ignoring all output can also be written as: command >/dev/null 2>&1 &

such a file output, each run will overwrite the existing file, if we want to append, but not overwrite, then use the >> symbol, so the command is: 1>>log 2>>error &

basically the parameters of the various writing are here, but there is a problem. This "background" process is no problem when the shell is open, and if we close the shell window or even exit SSH login or VNC login, then the process will end automatically. So if you want to exit the window or even exit login still keep the program running, plus nohup, shape: nohup command 1>output 2>&1 &

that's probably the case.

This article from "Empty" blog, declined reprint!

Linux background operation & symbols, nohup commands, output redirection and other usage methods

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.