nohup & disown command in linux

Last Updated : 4 Feb, 2026

In Linux, the nohup (no hang up) command and the disown shell built-in are used to run processes in the background and detach them from the current shell session. This allows processes to continue running even after the terminal session is closed or the user logs out. In this guide, we will explore how to use nohup and disown with practical examples.

1. Using nohup Command:

The nohup command is used to run a command immune to hangups (i.e., it keeps running even if the user logs out or the terminal is closed).

Basic Usage:

nohup command [arguments] &
  • Example:
nohup ./my_script.sh &

This command runs the script my_script.sh in the background and detaches it from the terminal.

Where does the output go?

By default, nohup redirects all output (stdout and stderr) to a file named nohup.out in the current directory. To avoid creating this file (or to save output elsewhere), use standard redirection:

# Redirect output to custom_log.txt
nohup ./script.sh > custom_log.txt 2>&1 &

2. Using disown Built-in:

The disown command is a shell built-in that is used to remove jobs from the shell's job table.

Basic Usage:

disown [options] [job_spec]
  • Example:
disown -h %1

This command removes the job with job ID 1 from the shell's job table.

Additional Tips:

  • Viewing Background Jobs:
jobs

This command displays a list of jobs running in the background.

  • Bringing a Background Job to the Foreground:
fg %1

This command brings the job with job ID 1 to the foreground.

Comparison: When to use which?

Featurenohupdisown
When to use?Before starting the command.After the command is already running.
Output?Saves to nohup.out by default.Does not save output (unless redirected manually).
PurposePlanning ahead for long tasks.Fixing a mistake (forgetting to background).
Comment
Article Tags:

Explore