nohup Command in Linux with Examples (original) (raw)

Last Updated : 6 Nov, 2025

The nohup (short for no hang up) command in Linux allows a process to continue running even after the user has logged out or the terminal is closed. It ignores the HUP (hangup) signal, which would normally terminate a running process when the session ends.

Example

Starting a Process Using Nohup

To start a process using Nohup, simply prepend the desired command with nohup. For example, if you want to execute a bash script named geekfile.py using Nohup, you would use the following command:

nohup bash geekfile.sh

**Output:

nohub bash

To redirect the output to the **output.txt file:

nohup bash geekfile.sh > output.txt

**Output:

nohu bash output.txt

Nohup Command Syntax

The syntax for using the Nohup command is straightforward:

nohup command [options] &

Starting a Process in the Background Using Nohup

To run the command in the background, the '****&'** symbol is appended at the end of the command. After executing, it doesn’t return to the shell command prompt after running the command in the background. It can be brought back to the foreground with the **fg command.

nohup bash geekfile.sh &
fg

**Output:

nohup bash script

**Note: The number within square brackets represents the **job id and the number next to it is the **process id.

**To run multiple commands in the background

nohup command can be used to run multiple commands in the background.

nohup bash -c 'commands'

**Example:

nohup bash -c 'cal && ls'

**Output:

To run multiple commands in the background:

Here, the output will be by default stored in **nohup.out. To redirect it, type:

nohup bash -c 'commands' > filename.txt

**Example:

nohup bash -c 'cal && ls' > output.txt

**Output:

Storing the output in output file

**Checking the version of Nohup

Checking the version of Nohup is a simple process. You can typically check the version of Nohup installed on your system by using the ` --version` flag. Simply execute the following command:

nohup --version

**Output:

nohup version