nohup Command: Usage, nohup.out, and Keeping Jobs Running After the Terminal Closes
To keep a job running after you close the terminal or lose your SSH connection, start it with the nohup command. nohup runs the command with the hangup signal (SIGHUP), which arrives when a terminal closes, set to be ignored. When a sleep started with nohup and a sleep started without it were run together on an AlmaLinux 9 server and the terminal was closed, only the one started with nohup was left running.
The output below comes from an AlmaLinux 9.8 server (root account) and a Debian 12 server (regular account). A sleep stood in for a long-running job, and only the PID received at launch was given when stopping it. Times are printed in UTC.
1️⃣ How to use the nohup command
Put nohup in front of the command to run, and use the & at the end of the command for background execution. According to the official GNU manual, nohup itself does not send the command to the background, so without the & the prompt does not come back until the command finishes.
nohup sleep 300 &[1] 3431609
nohup: ignoring input and appending output to 'nohup.out'[1] is the job number and 3431609 is the PID of the started process. The message that followed says the process does not read keyboard input and appends its output to the file nohup.out.
The PID of the job you just started is kept in $!, so run [echo $!] right after starting it and note the number down; use that same number when you check its status or stop it.
echo $!3431609When a terminal closes, the shell receives the hangup signal and sends the same signal to the jobs it started (per the official Bash manual). To check this, [nohup sleep 300 &] and, without nohup, [sleep 301 &] were started together in a new terminal.
sleep 301 &[2] 3432892jobs -l[1]- 3432883 Running nohup sleep 300 &
[2]+ 3432892 Running sleep 301 &With both jobs Running, the terminal window was closed and the two PIDs were checked with ps from another shell.
ps -p 3432883,3432892 -o pid,stat,etime,cmd PID STAT ELAPSED CMD
3432883 S 00:05 sleep 300Only sleep 300, started with nohup, was left; sleep 301, started without nohup, ended when the terminal closed.
A process started with nohup is like a phone in Do Not Disturb mode.
nohup is a command from the coreutils package. Check the installed version with the first line of --version. The AlmaLinux 9.8 server had 8.32 and the Debian 12 server had 9.1.
nohup --version | head -1nohup (GNU coreutils) 8.32nohup --version | head -1nohup (GNU coreutils) 9.12️⃣ nohup.out and output redirection
If you do not choose where the output goes, nohup appends the command's output to nohup.out in the current folder. The newly created nohup.out was 0 bytes, and its permissions were -rw-------, readable and writable only by the user who created it.
ls -l nohup.out-rw------- 1 root root 0 Oct 28 23:04 nohup.outThe official GNU manual says nohup creates nohup.out so that only the user who created it can read and write it, regardless of the umask setting. If it cannot write to the current folder, it writes to $HOME/nohup.out in the home folder, and if it cannot write there either, it does not run the command.
When a command that produces output was run with nohup, the output stayed in nohup.out after the command finished.
nohup sh -c 'echo start; sleep 2; echo end' &[1] 3431985
nohup: ignoring input and appending output to 'nohup.out'cat nohup.outstart
end
[1]+ Done nohup sh -c 'echo start; sleep 2; echo end'Done on the last line is the shell's notice that the job has finished. nohup.out is not recreated on each run but appended to at the end of the same file, so if you start several jobs from the same folder, their output gets mixed in one file.
To keep a separate log for each job, set the output file with > and send error output to the same file with 2>&1.
nohup sh -c 'echo start; sleep 300' > job.log 2>&1 &[1] 3432059cat job.lognohup: ignoring input
startWith 2>&1 added, the terminal showed only the job number and PID, and nohup's notice [nohup: ignoring input] was written to the first line of the log file.
If you add only > and leave out 2>&1, the terminal shows a notice that error output is being sent to the standard output file.
nohup sleep 300 > job2.log &[2] 3432097
nohup: ignoring input and redirecting stderr to stdoutSend the output of jobs you do not need to keep to /dev/null. Here too, the terminal showed only the job number and PID.
nohup sleep 300 > /dev/null 2>&1 &[3] 3432137The table below shows where the output went and what appeared in the terminal for each of the four ways of running it.
| How it is run | Where output goes | Message in the terminal |
|---|---|---|
| nohup command & | nohup.out in the current folder | nohup: ignoring input and appending output to 'nohup.out' |
| nohup command > file & | The given file (error output included) | nohup: ignoring input and redirecting stderr to stdout |
| nohup command > file 2>&1 & | The given file | None (the notice goes to the first line of the file) |
| nohup command > /dev/null 2>&1 & | Discarded | None |
3️⃣ Checking and stopping nohup processes
The jobs list shows only jobs started from the current shell, so after you close the terminal and log in again, check a nohup process with ps -p and its PID. While you are still in the same shell, jobs -l shows the job number, PID and state together.
jobs -l[1]+ 3431609 Running nohup sleep 300 &Put a PID after ps -p and pick columns with -o, and only that process's line is shown. S in STAT means it is sleeping while it waits for an event, and ELAPSED is the time since it started.
ps -p 3431609 -o pid,stat,etime,cmd PID STAT ELAPSED CMD
3431609 S 00:03 sleep 300To stop it, use kill followed by the PID.
kill 3431609kill printed nothing, and when jobs was run next, the job appeared as Terminated and then dropped out of the list.
jobs[1]+ Terminated nohup sleep 300Running ps again with the same PID printed only the header, which confirmed that the process had ended.
ps -p 3431609 -o pid,stat,etime,cmd PID STAT ELAPSED CMDnohup ignores only the hangup signal, so sending that same signal directly with [kill -HUP] does not end the process. kill -HUP was sent to sleep 305, started with nohup, and to sleep 306, started without it.
kill -HUP 3437119 3437128A check with jobs -l then showed only the nohup one still Running, while sleep 306 ended with Hangup.
jobs -l[1]- 3437119 Running nohup sleep 305 &
[2]+ 3437128 Hangup sleep 306If you give kill no signal, it sends SIGTERM, so a job started with nohup also ends with [kill PID].
4️⃣ nohup command vs. disown, and options
🔲 nohup vs. disown
disown is a bash builtin for jobs that are already running: it detaches a job started with & but without nohup from the terminal's hangup signal later on. disown does not send output to nohup.out, so for a job that produces output, set where the output goes with > file when you start it.
According to the official Bash manual, disown without options removes the job from the jobs list, while disown -h keeps it in the list and only stops the hangup signal from reaching it. First, sleep 302 was started and then disown was run.
sleep 302 &[1] 3433230disowndisown printed nothing, and jobs -l run right after it also returned nothing.
jobs -lNext, sleep 303 was started and disown -h was run on job number %1.
sleep 303 &[1] 3433343disown -h %1A check with jobs -l showed the job still in the list.
jobs -l[1]+ 3433343 Running sleep 303 &One more sleep, sleep 304, was started with no handling at all, the terminal was closed, and the three PIDs were checked from another shell.
sleep 304 &[2] 3433474ps -p 3433230,3433343,3433474 -o pid,stat,etime,cmd PID STAT ELAPSED CMD
3433230 S 00:11 sleep 302
3433343 S 00:08 sleep 303The two jobs given disown and disown -h were left, and only sleep 304, which had no handling, ended. The four methods compare as follows.
| Method | When to use | jobs list | After the terminal closes | Output |
|---|---|---|---|---|
| nohup command & | At launch | Remains | Remains | nohup.out or the given file |
| command & then disown | After launch | Skipped | Remains | Unchanged |
| command & then disown -h | After launch | Remains | Remains | Unchanged |
| command & only | — | Remains | Ended | Unchanged |
For work where you need to bring the session screen back and keep typing, a terminal multiplexer such as tmux is the right fit; for work you start once and only collect the result from a file, nohup is enough.
🔲 nohup command options
📌 Main options: results from this article
| Option | Task | Result in this article | |
|---|---|---|---|
| --version | Prints version information and exits | AlmaLinux 9.8 server: nohup (GNU coreutils) 8.32, Debian 12 server: nohup (GNU coreutils) 9.1 |
📎 Other options: per the official manual
| Option | Task | |
|---|---|---|
| --help | Prints help and exits |
🔲 nohup command simulator
In the simulator below, start a job with nohup, close the terminal and reconnect with the 🔌 chip, and see for yourself which processes are left.
🔢 FAQ & Recommended Content
Scheduling
Linux: crontab Setup
How to set up crontab, the Linux scheduler that registers jobs to repeat at set times, such as backups or log cleanup.
Processes
Linux top Command (Checking CPU and Memory Usage)
The top command, which shows CPU and memory usage per process in real time.
ℹ️ Affiliate Disclosure
This site's content contains affiliate links. When a visitor buys a product or service through one of them, the site receives a commission from the seller. The amount the buyer pays(it goes down during event discounts ↓)does not go up. Posted prices, discounts, and stock reflect the time of writing and may differ, so confirm with the seller before buying. Products are chosen and reviewed by our own standards, and commissions do not affect the order or content of reviews.