Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

nohup

Run a command that keeps running after you log out (it ignores the hang-up signal).

Level
Everyday Linux
Group
Processes and jobs
Needs root
No
Package
coreutils

What it does

When you close a terminal, its processes get SIGHUP and stop. nohup COMMAND & makes the command ignore SIGHUP. Output that would go to the terminal goes to nohup.out (in the current folder, or in your home folder).

For real long-running work, a systemd unit (systemd-run) or tmux is often better.

How to write it

nohup COMMAND [ARGUMENT]...

Options 2

Most used

--help
Show help.
--version
Show the version.

Examples 10

$ run as a normal user# run as root (or with sudo)

  1. 1Keep a job running after logout

    nohup ./long-task.sh &
    nohup: ignoring input and appending output to 'nohup.out'

    Log out and come back later.

  2. 2Choose the log file

    nohup ./long-task.sh > /var/tmp/task.log 2>&1 &

    Better than nohup.out in a random folder.

  3. 3Follow the output

    tail -f nohup.out

    See the progress.

  4. 4Long copy over SSH

    nohup rsync -a /data/ server2:/data/ > rsync.log 2>&1 &

    Survives a broken SSH connection.

  5. 5Check that it still runs

    pgrep -af long-task.sh

    After you log in again.

  6. 6With low priority

    nohup nice -n 19 ./report.sh > report.log 2>&1 &

    Long and quiet.

  7. 7Stop it later

    pkill -f long-task.sh

    nohup does not protect against SIGTERM.

  8. 8Better alternative: a transient systemd unit

    systemd-run --user --unit=longtask ./long-task.sh
    journalctl --user -u longtask -f

    Logs in the journal, easy to stop with systemctl.

  9. 9Alternative: tmux

    tmux new -s work

    Detach with Ctrl+B D, attach later with tmux attach -t work.

  10. 10Mind the lingering setting

    loginctl enable-linger lisa

    With systemd, user processes may be killed at logout unless linger is on (or KillUserProcesses=no).

Exit codes

0The exit status of the command.
125nohup failed.
126The command could not be run.
127The command was not found.

Full manual

This page explains the command in simple words. The original manual has every detail.

In your terminal: man nohup