nohup Command in Linux: Background Jobs and Output

By 

•

Updated on

•

11 min read

Using the nohup command in Linux to run commands after logout

You start a backup script on a remote server, close your laptop, and the next morning the job is dead. The shell sent it a SIGHUP (hangup) signal when your session ended. The nohup command prevents exactly that: it runs a given command and ignores SIGHUP, so the process keeps running even after you log out or close the terminal.

This guide explains how to use nohup to run commands that survive session disconnects, redirect their output, and manage them after they start.

nohup Syntax

txt
nohup [OPTION]... COMMAND [ARG]...

nohup supports only two options, --help and --version. The Rust implementation that ships with Ubuntu 26.04 also accepts the short forms -h and -V. In normal use, everything after nohup is treated as the command to execute.

Running a Command with nohup

To run a command that will not be killed when the terminal closes, prefix it with nohup:

Terminal
nohup mycommand
output
nohup: ignoring input and appending output to 'nohup.out'

nohup runs mycommand in the foreground and redirects its output to a file called nohup.out in the current working directory . If you do not have write permission in that directory, the file is created in your home directory instead.

If you log out or close the terminal, the process continues running. To return control to the shell while the command runs, you must also start it as a background job.

What “ignoring input and appending output to nohup.out” Means

The message nohup: ignoring input and appending output to 'nohup.out' is not an error. It is nohup telling you two things: standard input is detached from the terminal, so the command cannot read from the keyboard, and everything the command writes to standard output or standard error is appended to the nohup.out file.

The message confirms output redirection, but nohup prints it before attempting to run the command. Check the log and process status to confirm that the command started. To read the log:

Terminal
cat nohup.out

When you redirect both standard output and standard error yourself, as shown in the sections below, nohup does not create nohup.out and nothing appears in the terminal. GNU nohup still prints nohup: ignoring input to standard error. That line ends up at the top of your log file. To keep it out, redirect standard input too:

Terminal
nohup mycommand > mycommand.out 2>&1 < /dev/null &

The wording of the message depends on which streams are still connected to the terminal:

MessageWhen it appears
ignoring input and appending output to 'nohup.out'Input, output, and errors are all connected to the terminal
ignoring input and redirecting stderr to stdoutYou redirected standard output, and errors follow it into the same file
ignoring inputYou redirected standard output and standard error
appending output to 'nohup.out'You redirected standard input, and output goes to nohup.out

Ubuntu 26.04 uses the Rust nohup from uutils coreutils. It prints the first message whenever output goes to nohup.out. When you redirect output yourself, it prints nothing.

Running in the Background

Running nohup in the foreground is not very useful because you cannot interact with the shell until the command finishes. To run the command in the background , append & at the end:

Terminal
nohup mycommand &
output
[1] 25177

The output shows the shell job ID in brackets and the process ID. You can continue using the terminal immediately while the command runs in the background.

To bring the command back into the foreground, use the fg command . To check which background jobs are active in the current shell, use jobs:

Terminal
jobs
output
[1]+  Running                 nohup mycommand &

Redirecting Output to a File

By default, nohup sends all output to nohup.out. To redirect to a different file, use standard shell redirection.

Redirect both standard output and standard error to a single file:

Terminal
nohup mycommand > mycommand.out 2>&1 &

The 2>&1 part redirects standard error (file descriptor 2) to the same place as standard output (file descriptor 1), so both streams end up in mycommand.out.

Redirect standard output and standard error to separate files:

Terminal
nohup mycommand > mycommand.out 2> mycommand.err &

If you do not need the output at all, redirect it to /dev/null:

Terminal
nohup mycommand > /dev/null 2>&1 &

For more on redirection syntax, see the guide on redirecting stderr and stdout .

Reading nohup Output

When a nohup process writes to nohup.out over a long period, you can follow the output in real time with tail -f :

Terminal
tail -f nohup.out

This displays new lines as they are written to the file. Press Ctrl+C to stop following.

To see only the last 20 lines of the file:

Terminal
tail -20 nohup.out

Checking and Managing nohup Processes

After you start a nohup process and close the terminal, the shell job ID is no longer available. You can find the process using ps :

Terminal
ps aux | grep mycommand
output
john     25177  0.2  1.3 124568 53712 ?        S    14:03   0:05 mycommand
john     25391  0.0  0.0   6876  2048 pts/1    S+   14:20   0:00 grep --color=auto mycommand

The ? in the TTY column confirms the process is no longer attached to a terminal. The second line is the grep process itself. pgrep skips it and prints the PID with the full command line:

Terminal
pgrep -af mycommand
output
25177 mycommand

To stop the process, send it a signal with kill :

Terminal
kill 25177

If the process does not respond to a regular SIGTERM, force it with SIGKILL:

Terminal
kill -9 25177

Using nohup with sudo

When you need to run a nohup process as root and write its output to a root-owned location, run the command and its redirections through a root shell:

Terminal
sudo sh -c 'nohup ./long-task.sh > /var/log/long-task.out 2>&1 &'

The shell processes redirections before running sudo. With sudo nohup ./long-task.sh > /var/log/long-task.out, your own user opens the file and gets Permission denied. Wrapping the full command with sudo sh -c ensures that root opens the file in /var/log.

A background sudo job cannot ask for a password. Both nohup sudo command & and sudo nohup command & stop at the password prompt, and jobs lists them as Stopped. In the sh -c form, sudo runs in the foreground and asks for the password first. Only then does the job go to the background. You can also authenticate with sudo -v and start the background job afterwards. sudo uses the cached credentials and does not prompt again.

Practical Examples

Run a backup script that continues after you log out:

Terminal
nohup /usr/local/bin/backup.sh > ~/backup.log 2>&1 &

Download a large file with wget in the background:

Terminal
nohup wget https://example.com/large-file.tar.gz &

wget writes its own progress to nohup.out, so you can check tail -f nohup.out to monitor the download.

Run a Python script that processes data overnight:

Terminal
nohup python3 -u process_data.py > process.log 2>&1 &

The -u option turns off Python output buffering. Without it, Python buffers print() output written to a file, and process.log can stay empty for minutes.

Alternatives to nohup

nohup is the simplest way to keep a command running after logout, but other tools offer more control.

disown

disown is a shell builtin that detaches a running job from the current shell. Unlike nohup, you can use it on a process that is already running:

Terminal
mycommand &
disown %1

After disown, the shell will not send SIGHUP to that job when you log out. The difference from nohup is that disown does not redirect output, so if the process writes to the terminal and the terminal closes, the process may fail with a write error.

Screen

Screen is a terminal multiplexer that lets you create persistent sessions. You can detach from a session and reattach later, even from a different SSH connection. This gives you full interactive access to the process, not just background execution.

tmux

tmux is a modern terminal multiplexer and a popular alternative to Screen. It offers the same session persistence with a more flexible interface for splitting panes and managing multiple windows.

For simple background tasks where you do not need to interact with the process later, nohup is the most straightforward option. Use Screen or tmux when you need to reattach and see live output.

Quick Reference

For a printable quick reference, see the Job Control cheatsheet .

CommandDescription
nohup command &Run a command in the background, immune to hangup
nohup command > file.out 2>&1 &Redirect all output to a custom file
nohup command > file.out 2>&1 < /dev/null &Redirect all streams, with no “ignoring input” line
nohup command > /dev/null 2>&1 &Discard all output
tail -f nohup.outFollow nohup output in real time
ps aux | grep commandFind a running nohup process
pgrep -af commandFind a nohup process without matching grep itself
kill PIDStop a nohup process gracefully
kill -9 PIDForce-stop a nohup process
jobsList background jobs in the current shell
disown %1Detach job 1 from the shell (no SIGHUP on logout)

Troubleshooting

nohup: failed to run command ‘./script.sh’: Permission denied
The command you passed to nohup is not executable. Check the file permissions with ls -l and add the execute bit with chmod +x script.sh if needed. In this case, nohup exits with status 126.

nohup: failed to run command ‘script.sh’: No such file or directory
nohup looks for the command in your PATH, and the current directory is not part of it. Run a script from the current directory as ./script.sh, or pass the full path. The exit status is 127. On Ubuntu 26.04, the Rust nohup writes both of these errors to nohup.out instead of the terminal. If a job ends with Exit 126 or Exit 127 and no message, check that file.

nohup: ignoring input and appending output to ’nohup.out’
This is not an error. It confirms that standard input is disconnected and output is going to nohup.out, but it does not confirm that the command started successfully. Check the log and process status to verify that the command is running.

The process stopped after logout even though I used nohup
nohup sets SIGHUP to be ignored when the command starts. A program can install its own handler and still exit on hangup. A pipeline is another common cause, since nohup covers only the first command (see the FAQ below). Some systems also end the whole login session at logout. With KillUserProcesses=yes in /etc/systemd/logind.conf, systemd terminates every process in the session, nohup or not. Ubuntu and Debian default to no. If your system has the setting enabled, turn on lingering with loginctl enable-linger and start the command with systemd-run --user. The command then runs outside the login session.

nohup.out stays empty while the command runs
Many programs buffer their output when it goes to a file instead of a terminal. They write it in large blocks. For Python, use python3 -u or set PYTHONUNBUFFERED=1. For programs that use the C standard library, such as grep, run the command through stdbuf -oL to flush output line by line. stdbuf has no effect on Python.

nohup.out is growing very large
Redirect output to /dev/null if you do not need it (nohup command > /dev/null 2>&1 &), or redirect to a specific log file and set up log rotation.

FAQ

What does nohup stand for?
nohup stands for “no hangup.” It prevents the SIGHUP signal from reaching the command, so the process is not terminated when the controlling terminal closes.

What is the difference between nohup and disown?
nohup must be used before starting the command. It redirects output and makes the process immune to SIGHUP from the start. disown is a shell builtin that detaches an already-running job from the shell, but it does not redirect output. If you forgot to use nohup, you can background the process with Ctrl+Z and bg, then run disown to detach it.

What is the difference between nohup and screen/tmux?
nohup simply prevents a process from being killed on logout. You cannot interact with the process after it starts. Screen and tmux create persistent terminal sessions that you can detach from and reattach to later, giving you full interactive access.

Where does nohup save its output?
By default, nohup writes to nohup.out in the current working directory. If the directory is not writable, it writes to $HOME/nohup.out. You can override this with shell redirection.

Can I use nohup with a pipeline?
Yes, but you need to wrap the pipeline in a shell:

Terminal
nohup bash -c 'command1 | command2 > output.log 2>&1' &

Without the bash -c wrapper, nohup only applies to the first command in the pipeline.

Conclusion

nohup is the simplest way to keep a process running after you close a terminal or disconnect from SSH. For tasks where you need to reattach and interact with the process later, consider using screen or tmux instead.

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 1000+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page