System and processes

The nohup command

Runs a command that ignores the hangup signal (SIGHUP), so it keeps running after you close the terminal or the SSH session. If you do not redirect the output, it is saved to nohup.out.

Syntax

nohup comando [argumentos]Try it in the terminal →

Most useful options

&Puts it in the background and gives the prompt back. It goes at the end of the command.
> archivo 2>&1Saves output and errors to a file, instead of nohup.out.
--Marks the end of nohup's options, useful if the command starts with a dash.
--helpShows the help and exits.

Copy-ready examples

$ nohup ./backup.sh > backup.log 2>&1 &Starts the script in the background and saves its output and errors to backup.log.

Example output

[1] 4821
$ nohup python3 servidor.py &Without a redirection, nohup says where the output goes.

Example output

nohup: ignoring input and appending output to 'nohup.out'
$ nohup make -j4 > build.log 2>&1 &A long build that keeps going after you close the session.
$ ps -p 4821 -o pid,cmdChecks that the process is still alive and what it is running.

Example output

  PID CMD
 4821 python3 servidor.py
$ kill 4821Stops the process if needed: nohup does not protect it from kill.

You can try them in the browser terminal: it does not touch your computer.

Common errors

MessageCauseFix
nohup: missing operandIt was called without a command: nohup needs at least the program you want to run.Write the command after nohup, for example nohup ./script.sh &.
nohup: failed to run command 'nosuchcmd_xyz': No such file or directoryThe program does not exist or is not in PATH, or the name has a typo.Use the full path, such as ./script.sh, or check the name with which.
nohup: ignoring input and appending output to 'nohup.out'It is not an error: nohup warns that the output goes to nohup.out because you did not redirect it.Redirect with > file 2>&1 if you want your own log and no notice.

Typical mistakes

  • nohup does not survive a reboot: for that, use a systemd service.

Differences from similar commands

  • disown: Removes a job from the shell's job table. With disown -h it will not get SIGHUP on exit, even if it is already running.
  • screen: Creates sessions you can reattach and watch live, with several windows inside. Handier for interactive tasks.

Security

If the script takes passwords on the command line, they are visible in ps: use environment variables or a file with 600 permissions. Do not run unreviewed downloaded scripts with nohup: they will keep running after you log out.

Related commands

FAQ

Where do I see the output if I do not redirect it?

In nohup.out, in the directory where you ran the command. If it already exists, the output is appended.

Why does the terminal wait without &?

Because the command runs in the foreground. With & the prompt returns and the shell shows the job number.

More System and processes commands

Learn to actually use it

The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.

Start the free course