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 redi­rect­ed 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­pli­ca­tion. Under certain cir­cum­stances, however, it’s necessary for this signal not to be sent. This is the case if an ap­pli­ca­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­b­u­tions like Debian and Ubuntu and therefore doesn’t need to be installed sep­a­rate­ly. 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 au­to­mat­i­cal­ly redi­rect­ed 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 pa­ra­me­ters that can be cus­tomized. 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 au­to­mat­i­cal­ly redi­rect­ed 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