Using the Linux command nohup, your system ignores the hangup command HUP. This lets processes continue to run in the back­ground. Its output is then re­dir­ec­ted to the file nohup.out or another file of your choice.

What is Linux nohup?

To un­der­stand what the Linux nohup command is, it’s worth looking at SIGHUP. This is a signal that is generated under Linux, among other things, when there’s a con­nec­tion failure on a data line between the operating system and another ap­plic­a­tion. Under certain cir­cum­stances, however, it’s necessary for this signal not to be sent. This is the case if an ap­plic­a­tion is to continue running even after the user has logged off from the system. To suppress the signal and allow programs to continue running in the back­ground, Linux nohup is used.

How does the Linux nohup command work?

Linux nohup is included in all common Linux dis­tri­bu­tions like Debian and Ubuntu and therefore doesn’t need to be installed sep­ar­ately. You can use it to instruct the system to run a specific program in the back­ground, thus detaching it from the login shell. Any output is auto­mat­ic­ally re­dir­ec­ted to the nohup.out folder. For longer processes this has the advantage that you can log off without in­ter­rupt­ing the process.

What does the Linux nohup syntax look like?

The basic syntax of the Linux nohup command always looks the same:

$ nohup [Command] [Argument] [&]
bash

‘[Command]’ and ‘[Argument]’ are para­met­ers that can be cus­tom­ised. To allow processes to continue running in the back­ground after logging off, use ‘[&]’.

What options does the nohup command have?

Linux nohup doesn’t accept any options other than the two standards ‘-h’ or ‘–help’ and ‘-v’ or ‘–version’. Only when re­frain­ing from entering a parameter for ‘[command]’, is the option ‘-p’ or ‘–parents’ allowed.

Examples for the Linux nohup command

Finally, to help you un­der­stand how the command works, we’ll show you a few examples.

$ nohup bash example.sh
bash

This executes the command in the fore­ground. The output of the command is auto­mat­ic­ally re­dir­ec­ted to the file nohup.out.

$ nohup bash example.sh > output.txt
bash

This command redirects the output to the output.txt document.

$ nohup bash example.sh &
bash

By using this input, the command will persist and continue execution in the back­ground. If you wish to reverse this and bring the command back to the fore­ground, you can execute the fg command.

Go to Main Menu