Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

The nohup Command in Linux

Keep a command running after you close the terminal or lose your SSH connection.

How-To Guides2 min read3 steps1 screenshot

What is nohup

nohup means "no hang up". Normally, when you close a terminal or your SSH session drops, the shell sends a hang-up signal (SIGHUP) to its programs and they stop. nohup makes a command ignore that signal, so it keeps running.

Why use nohup

  1. Run long scripts and jobs that take hours.
  2. Start background jobs you do not need to watch.
  3. Protect work on a remote server when the SSH connection is unstable.

Use it

Check the version:

nohup --version
The nohup version

Syntax:

nohup command arguments &
  • nohup keeps the command alive after logout.
  • command is what you run.
  • arguments are its options.
  • & puts it in the background so you get your prompt back.

Example:

nohup python3 long_running_script.py &

By default the output goes to a file named nohup.out in the current folder.

Send output to your own files

nohup command arguments > output.log 2> error.log &

Or put both in one file:

nohup command arguments > output.log 2>&1 &

Run a Bash script

nohup ./process_data.sh &

Make the script executable first with chmod +x process_data.sh.

Set the working directory

nohup can run only one program, not a shell command list like cd. Use a shell:

nohup sh -c 'cd /data && python3 compute_results.py' > compute.log 2>&1 &

Check and stop the job

Show the process:

ps aux | grep long_running_script

or

jobs

Stop it:

kill PID

Watch the log live:

tail -f output.log

nohup or something else

  • screen or tmux let you come back to the live session.
  • systemd services are better for long-lived server programs that must start at boot.

Quick recap

  • nohup command > out.log 2>&1 & keeps a job running after logout.
  • Use tail -f out.log to follow it.