nohup Command in Linux with Examples
Last Updated :
06 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.
- nohup prevents processes from being stopped when the user logs out.
- It automatically redirects the command’s output to a file named nohup.out (if no other output file is specified).
- It can be used with & to run the process in the background.
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:

To redirect the output to the output.txt file:
nohup bash geekfile.sh > output.txt
Output:

Nohup Command Syntax
The syntax for using the Nohup command is straightforward:
nohup command [options] &
`command`: Specifies the command or script that you want to execute.`[options]`: Optional arguments or flags that modify the behavior of the command.`&`: Placing an ampersand (&) at the end of the command instructs the shell to run the command in the background.
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:

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:

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:

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:
What is the main purpose of the nohup command in Linux?
-
To run a process with higher priority
-
To prevent a process from stopping after logout
-
To pause a running process
-
To delete a process automatically
Explanation:
nohup prevents a process from getting terminated when the terminal closes or the user logs out.
Which command correctly runs a script in the background using nohup?
Explanation:
Appending & runs the process in the background along with nohup.
Which command correctly stores nohup output in output.txt?
-
nohup bash geek.sh output.txt
-
nohup bash geek.sh > output.txt
-
nohup > output.txt bash geek.sh
-
nohup bash > output.txt geek.sh
Explanation:
Using > output.txt redirects nohup output to the file.
Which command correctly uses nohup to run multiple commands in the background?
-
-
nohup bash -c 'cal && ls' &
-
-
Explanation:
nohup bash -c 'commands' is the correct method to execute multiple combined commands.
Quiz Completed Successfully
Your Score : 2/4
Accuracy : 0%
Login to View Explanation
1/4
1/4
< Previous
Next >
Explore
Getting Started with Linux
Installation with Linux
Linux Commands
Linux File System
Linux Kernel
Linux Networking Tools
Linux Process
Linux Firewall
Shell Scripting & Bash Scripting
Linux Administrator System