nohup Run a command that survives logout
Starts a command and makes it ignore the hang-up signal, which a shell sends to its jobs when the terminal closes. You reach for it to leave a long job running after you close the window or disconnect from a remote machine.
Synopsis
nohup COMMAND [ARGUMENT]...
nohup COMMAND [ARGUMENT]... > FILE 2>&1 &
Common options
| Option or form | What it does |
|---|---|
COMMAND | The program to run. nohup has no options of its own on macOS besides the optional -- before the command |
> FILE | Shell redirection that sends the program's output to FILE instead of nohup.out |
2>&1 | Shell redirection that sends error messages to the same place as normal output |
& | Shell feature that runs the command in the background so you get your prompt back |
< /dev/null | Optional shell redirection that stops the program waiting for input from the terminal |
Examples
nohup echo hello > out.log 2>&1
nohup ./long-job.sh > job.log 2>&1 &
nohup ./long-job.sh > job.log 2>&1 < /dev/null &
nohup ./long-job.sh &
ps aux | grep '[l]ong-job'
Notes
- If standard output is a terminal and you do not redirect it, nohup appends the output to nohup.out in the current directory. If it cannot create that file there, it tries your home directory.
- nohup does not put the command in the background. Add & yourself, or the command keeps your terminal busy.
- Redirect output yourself with > file 2>&1 so you know where the log is. Several jobs started without redirection all append to the same nohup.out and the output gets mixed.
- nohup only ignores the hang-up signal. It does not protect against other signals, and it does not restart a program that crashes.
- For jobs you want to leave and come back to interactively, a terminal multiplexer such as tmux or screen is a better fit. For repeating jobs, use crontab.
See also
Last reviewed 2026-10-07.