Nohup command in Linux: nohup: assigning input and attaching output to‘ nohup.out ’

A few days ago, I found a giant cow’s AI learning website, which is easy to understand, funny and humorous. I can’t help sharing it with you. Click to jump to the tutorial.


1、 Using nohup in Linux

Under UNIX / Linux, for example, if you want a program to run in the background, many of them use & amp; at the end of the program to make the program run automatically.

For example, we need to run Weblogic in the background:
/ &

But many of our programs are not made into daemons like Weblogic. Maybe our programs are just ordinary programs, which usually use & amp; endings.

But if the terminal is shut down, the program will also be shut down.

But in order to be able to run in the background, we can use the nohup command.

For example, we have a To run in the background, use nohup:

nohup ./ &


[~]$ appending output to nohup.out

Well, prove that the program runs successfully, and put the output information of the program running into the current directory nohup.out Go to the file.

Nohup command

Purpose: Linux command usage, running command without hang up.

Syntax: nohup command [Arg…] [& amp;]

Description: the nohup command runs the command specified by the command parameter and any associated Arg parameters, ignoring all the up signals.

After logging off, use the nohup command to run the program in the background. To run the nohup command in the background, add & amp; (the symbol for “and”) to the end of the command.

nohup: ignoring input and appending output to ` nohup.out ‘ignore input and output, record information to nohup.out File.


2、 Using Linux redirection to solve the problem nohup.out No write permission problem

■ scene

When executing the nohup command, the following error without write permission often occurs.

nohup: ignoring input and appending output to ` nohup.out ‘
nohup: failed to run command `/etc/nginx_ ‘: Permission denied


■ Linux redirection:

0, 1 and 2 represent standard input, standard output and standard error message output respectively, which can be used to specify the standard input or output to be redirected.

In general use, the default is the standard output, which is 1. When we need special use, we can use other labels.

For example, output the error information of a program to the log file. / program 2 & gt; log.

In this way, the standard output is still on the screen, but the error information will be output to the log file.


In addition, the redirection between 0, 1 and 2 can also be realized. 2 & gt; & amp; 1: redirect error messages to standard output.

There is also a special file / dev / null under Linux, which is like a bottomless hole. All the information redirected to it will disappear without a trace.

This is useful to redirect the output to / dev / null when we don’t need to echo all of the program’s information.

If you want both normal output and error information not to be displayed, redirect both standard output and standard error to / dev / null, for example:

# ls 1>/dev/null 2>/dev/null

Another way is to redirect the error to standard output and then to / dev / null, for example:

# ls >/dev/null 2>&1

Note: the order here cannot be changed, otherwise the desired effect cannot be achieved. At this time, redirect the standard output to / dev / null,

Standard errors are then redirected to standard output.

Since standard output has been redirected to / dev / null, standard error will also be redirected to / dev / null, so everything is quiet.


About nohup

When using the nohup command, it is often due to the output nohup.out The path for does not have write permission and nohup cannot be used.

This is a way to use Linux redirection to nohup.out Redirect to a path with write permission, or throw it directly into / dev / null.

nohup ./program >/dev/null 2>/dev/null &


nohup ./program >/dev/null 2>&1 &


3、 Using nohup to set background process

Introduction: sometimes you need to set up a background process on Linux, but when you close terminal, it will be killed by the system. How to make the background process run continuously?


nohup command-with-options &

When you tap the above command on the screen, the following information will appear on the screen:

$ nohup: ignoring input and appending output to ` nohup.out ’

Hit enter and exit nohup.out In the current interface, enter the normal command line.

Output log information:

The next output log information will be output to nohup.log . that is, the log information output on the screen is directly output to nohup.log Documents.

Flag of background process:

If a command is only identified by & amp;, it is running in the background in the current session. If the current session is closed or the current terminal tool is closed, its affiliated processes will be closed.

The normal running background process needs nohup and & amp; to ensure its normal running in the background.




Transferred from:




Read More: