Open In App

nohup Command in Linux with Examples

Last Updated : 06 Nov, 2025
Comments
Improve
Suggest changes
11 Likes
Like
Report

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:

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] &
  • `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:

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
Suggested Quiz
4 Questions

What is the main purpose of the nohup command in Linux?

  • A

    To run a process with higher priority

  • B

    To prevent a process from stopping after logout

  • C

    To pause a running process

  • D

    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?

  • A

    nohup script.sh


  • B

    nohup script.sh &


  • C

    & nohup script.sh


  • D

    nohup & script.sh

Explanation:

Appending & runs the process in the background along with nohup.

Which command correctly stores nohup output in output.txt?

  • A

    nohup bash geek.sh output.txt

  • B

    nohup bash geek.sh > output.txt

  • C

    nohup > output.txt bash geek.sh

  • D

    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?

  • A

    nohup cal && ls &

  • B

    nohup bash -c 'cal && ls' &

  • C

    nohup (cal && ls) &

  • D

    nohup 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