DevOps Pills - Unix nohup

January 16, 2019

How to run a command even after logout

Nohup stands for no hang up.

The syntax is:

nohup /path/to/command-name arg1 arg2 &
  • command-name: is name of shell script or command name
    • you can pass argument to command or a shell script.
  • &: nohup does not automatically put the command in background
    • you must do that explicitly, by ending the command line with an & symbol

How to not create nohup.out

nohup /path/to/command-name arg1 arg2 >/dev/null 2>&1 &
  • 1 standard output file descriptor
    • if you don’t specify a number the output redirection defaults to file descriptor 1 (> is the same as 1>)
  • 2 standard error file descriptor
  • >& means: “send the file descriptor on the left (2) wherever the file descriptor on the right (1) is going”
  • >/dev/null means: “send standard output to /dev/null”

So the sequence >/dev/null 2>&1 means “send standard output to /dev/null and then send standard error to wherever standard output is going” (/dev/null in our case).

“throw away whatever this command writes”