
Oftentimes you’ll be in a situation where you want to run a command on a remote machine that will take a long time to complete, but you want to be able to issue the command and then log off and have that command run in the background.
There are many ways you could achieve this, perhaps by using cron or at to schedule the command to run right away. However, there is a better way.
There is a command called nohup built into both the GNU toolset, and most shells, which allows you to run a command in this way. It is so called because the command being run is executed ignoring ‘hang up’ signals, which are given when you close the terminal you started the program from.
To use this, simply prefix your command with nohup, for example:
nohup wget bigfile
This will still run in the foreground, however, meaning that you will lose the ability to use that terminal while the command is executing. In most cases, you’ll want to use the ampersand (&) to run the command in the background.
nohup wget bigfile &
Now you can log off your remote machine, or close your terminal and the command will continue running in the background.
The output and errors from the command you run with nohup are stored in a file called nohup.out in the directory where you started the command, or your home directory if for some reason that’s not possible (e.g. permissions).


Scott wrote:
Great tip! Thanks.
# Posted on 08-Jul-08 at 7:12 pm
Nick wrote:
You can also use screen to accomplish the same thing, but you’ll be able to return to the controlling terminal after you close the session. It’s great for things like IRC. Check it out: http://www.gnu.org/software/screen/
# Posted on 09-Jul-08 at 6:38 am
Saeid wrote:
Thanks
# Posted on 09-Jul-08 at 7:28 am
Uddit wrote:
+1 for screen. it’’s infintely useful.
# Posted on 09-Jul-08 at 8:52 pm
pvandewyngaerde wrote:
for a process you allreay started you can suspend first with ctrl+ z and then disown
# Posted on 10-Jul-08 at 8:49 am
FOSSwire » Using GNU Screen on a Remote Machine wrote:
[...] recently posted about using nohup to run a command, particularly on a remote machine, that keeps running even when you close the [...]
# Posted on 10-Jul-08 at 5:41 pm
Chape wrote:
Great tip, thanks!
pvandewyngaerde - I understand you can put a process in the background with crtl+z but you won’t be able to logout while it’s still running in the background. What do you mean by disowning it?
# Posted on 15-Jul-08 at 2:13 pm
Ashish Shukla wrote:
[abbe@chateau ~]$ help disown
disown: disown [-h] [-ar] [jobspec ...]
By default, removes each JOBSPEC argument from the table of active jobs.
If the -h option is given, the job is not removed from the table, but is
marked so that SIGHUP is not sent to the job if the shell receives a
SIGHUP. The -a option, when JOBSPEC is not supplied, means to remove all
jobs from the job table; the -r option means to remove only running jobs.
# Posted on 28-Jul-08 at 11:23 am
Cory Lievers wrote:
+1 for Screen as well, it works great.
But, I actually just learned about this nohup the other day. I’m currently setting up a raid (mdadm) and articles I’ve read on the raid monitoring - prefixed with nohup, then it runs in the background and sends an email if there are problems.
Thanks
# Posted on 28-Jul-08 at 2:35 pm