nohup
Overview
nohup runs a command immune to SIGHUP, so it keeps running after logout when started from a terminal. Output defaults to nohup.out if not redirected.
Syntax
nohup command [args...]
nohup command [args...] >file 2>&1 &When to use what
| Need | Prefer |
|---|---|
| Quick one-off after SSH logout | nohup … & or tmux/screen |
| Survives reboot | systemd user/system service or timer |
| Managed restart/logs | systemd-run / unit file |
| Interactive detach | tmux / screen |
Examples with Explanations
Classic background job
nohup ./long-job.sh > long-job.log 2>&1 &
echo $!Default nohup.out
nohup python train.py &
# writes ./nohup.outCheck later
tail -f long-job.log
ps -p <pid> -o pid,etime,cmdBetter: transient systemd unit
systemd-run --unit=longjob --user ./long-job.sh
journalctl --user -u longjob -fBetter: tmux session
tmux new -d -s train './long-job.sh'
tmux attach -t trainNotes
nohupdoes not daemonize fully; still a child process.
&backgrounds in the shell;nohupalone still attaches until backgrounded.
disownis a bash alternative after starting a job.