🎁 New User? Get 20% off your first purchase with code NEWUSER20 Register Now →
Menu

Categories

nohup Command

Intermediate Process Management man(1)

Run a command immune to hangups (keeps running after logout)

👁 11 views 📅 Updated: Mar 15, 2026
SYNTAX
nohup COMMAND [ARG]...

What Does nohup Do?

nohup (no hangup) runs a command immune to hangup signals, allowing it to continue running after you disconnect from a terminal session. When you close a terminal or SSH session, SIGHUP is sent to all processes — nohup prevents this from killing your process.

nohup redirects stdout to nohup.out (unless redirected) and makes the process immune to SIGHUP. It is essential for running long-running tasks on remote servers where SSH sessions may disconnect.

For more sophisticated background job management with multiple windows and reattachment, consider using screen or tmux instead.

Options & Flags

OptionDescriptionExample
basic Run command immune to hangup nohup long-running-task &
redirect Redirect output to specific file nohup ./script.sh > output.log 2>&1 &
disown Remove from shell job table nohup ./task.sh & disown

Practical Examples

#1 Run in background after logout

Runs backup script that survives terminal/SSH disconnection. Output goes to nohup.out.
$ nohup ./backup.sh &
Output: nohup: appending output to nohup.out

#2 Custom output file

Runs a long ML training job with output redirected to a specific log file.
$ nohup python3 train_model.py > training.log 2>&1 &

#3 Run and disown

Runs rsync completely detached from the terminal.
$ nohup rsync -av /data/ /backup/ > rsync.log 2>&1 & disown

#4 Check nohup output

Monitors the output of a nohup process in real-time.
$ tail -f nohup.out

#5 Multiple commands

Runs multiple commands as a single background task.
$ nohup bash -c "cd /app && make build && make deploy" > deploy.log 2>&1 &

#6 Run server permanently

Starts a Node.js server that persists after SSH disconnection.
$ nohup node server.js > server.log 2>&1 &

Tips & Best Practices

Always redirect stderr: Use 2>&1 to capture both stdout and stderr. Without it, error messages may be lost: nohup cmd > logfile 2>&1 &
screen/tmux is better: For interactive sessions you want to reconnect to, use screen or tmux. nohup is for fire-and-forget tasks.
nohup.out grows forever: Without explicit redirection, nohup appends to nohup.out in the current directory. This file can grow very large. Always redirect to a specific log file.

Frequently Asked Questions

How do I run a process that survives SSH disconnection?
Use nohup command > output.log 2>&1 &. The process will continue running after you log out.
Where does nohup output go?
By default, to a file called nohup.out in the current directory. Redirect explicitly: nohup cmd > mylog.txt 2>&1
What is the difference between nohup and screen/tmux?
nohup makes a process survive hangup but you cannot reattach to it. screen/tmux create virtual terminals you can detach from and reattach to later.

Master Linux with Professional eBooks

Curated IT eBooks covering Linux, DevOps, Cloud, and more

Browse Books →