When you run commands in Linux, they usually stop working when you close the system or log out of the terminal. This can be an issue if you were running processes like backups, updates, or even scripts that need multiple hours to complete.
This is where the Linux nohup command comes into play. It is short for no-hangup, which essentially means that the commands will keep on running even if the system is shut down or logged out.
In this guide, we will learn from different examples how the Linux nohup command helps to manage scripts and redirect outputs.
What Does the Linux nohup Command Do?
The Linux nohup (no hang up) command allows you to run another command in such a way that it would keep running even if you are logged out or you have closed the terminal.
Normally when a session ends, the system sends a SIGNUP, aka the hang-up signal to terminate all the processes running in the background. With nohup, the command then ignores the signal and continues running the processes until they finish.
Why and When to Use nohup
You should use the Linux nohup command in such cases:
Get exclusive access to all things tech-savvy, and be the first to receive
the latest updates directly in your inbox.
- When you are executing long-running tasks like backups, updates, or system scans.
- While running shell scripts that can be completed without any manual monitoring.
- Starting the server processes or services that must stay active.
- Working over the remote SSH sessions, where disconnections might kill the process.
To summarise, any tasks that do not require manual intervention or monitoring and can run even after the system shuts off, can benefit from the nohup command.
Related Article: Linux cat Command: A Complete Guide to Viewing and Combining Files
Basic Syntax of nohup Command
The general syntax of the nohup command is:
nohup command [arguments] &
- command → The command you want to run.
- [arguments] → Options or parameters for that command.
- & → Runs the command in the background (optional, but commonly used with nohup).
By default, the Linux nohup command redirects the output to a file called nohup.out if no output redirection is specified.
Running Commands in the Background with nohup
To run the Linux nohup command in the background so that it won’t stop after logout, you can combine nohup with ampersand (&):
nohup long_running_command &
- nohup ensures the process isn’t terminated by logout.
- & tells the shell to run it in the background, freeing up your terminal.
For example, to run a Python script in the background:
nohup python3 script.py &
This will keep the script.py running even after you disconnect. The output will be put in nohup.out unless you redirect it elsewhere.

Redirecting Output with nohup
By default, if you do not specify any other output file, nohup will redirect the command’s output to the nohup.out file in the current directory. However, you can control this using the redirection operators:
nohup command > output.log 2>&1 &
- > output.log → Saves standard output to output.log.
- 2>&1 → Redirects error messages (stderr) to the same file.
- & → Runs the process in the background.
Example:
nohup ./backup.sh > backup.log 2>&1 &
This keeps logs organized and makes troubleshooting easier.
Using nohup with Shell Scripts
You can also run shell scripts with the Linux nohup command. This is actually useful for automation, cron jobs, or scripts that need to perform long-running tasks.
Example:
nohup sh script.sh &
Or, if your script is executable:
nohup ./script.sh > script.log 2>&1 &
This makes sure that the script continues running even after logging out, and all the output is saved for review later.
Checking and Managing nohup Processes
Once a process has been started with the Linux nohup command, you can manage it similar to the other background processes.
- Check running jobs: jobs -l
- Find the process ID (PID): ps -ef | grep command_name
- Stop a process: kill -9 PID
If you didn’t note the PID when starting, you can always use ps or pgrep to track it down.
Common Mistakes and Troubleshooting
Mistake | What Happens | How to Fix |
Forgetting & | Command runs with nohup but keeps the terminal busy | Add & to run in the background |
No output redirection | Output is written to nohup.out, which may clutter your directory | Use > file.log 2>&1 to redirect |
Closing terminal without nohup | Process is killed with logout | Always use nohup (or an alternative) |
Hard to find logs | Default nohup.out is used | Redirect output to a specific file for clarity |
Process not starting | Permission errors with scripts | Make script executable with chmod +x script.sh |
Alternatives to nohup in Linux
While the Linux nohup command is super easy to execute, some situations might require a different set of commands, here are some advanced tools that you can employ at that point.
- screen → it allows you to create detachable sessions where the commands keep on running in the background even after you disconnect.
- tmux → it acts as a modern terminal multiplexer that allows you to run persistent sessions, splitting windows, and better control than screen.
- systemd services → for the background tasks that require daemons, creating a systemd service is a better option.
- disown → a shell built-in command that removes the job from the table so that it would not terminate on shutdown.
Conclusion
The Linux nohup command is one of those handy tools that ensures that your processes run way past the shutdown or logout instances. Whether you are running super-long scripts, starting the server processes, or managing the tasks remotely, Linux nohup is an excellent option!
FAQs
What is the nohup
command in Linux used for?
The nohup
command allows processes to continue running even after the user logs out or the terminal session ends. It ignores the hangup signal (SIGHUP) that would normally stop the process.
How do I run a command in the background using nohup
?
Use the syntax:nohup command > output.log 2>&1 &
This ensures the command runs in the background and continues after logout, while redirecting output to a log file.
Where does nohup
store output by default?
If no output file is specified, nohup
writes both standard output and errors to a file named nohup.out
in the current directory.