Originally published July 13, 2016 @ 10:18 am

This is a common question: how can I run nohup without creating the annoying nohup.out ? And the common answer is: you can’t. But this is not exactly true.

Some people have a dreadful habit of starting their applications using nohup with debug sent to stdout. The nohup.out will never be “rotated”, unlike a log file. It will keep growing until it consumes all available space. Even if you delete it or empty it out, the filesystem space will not be released, until the process wring to the file is terminated.

And so without further ado, lo and behold: running nohup without creating nohup.out:

nohup your_command </dev/null >/dev/null 2>&1 &

And here’s a little example. First, I rsync /etc to /etc_mirror using nohup to keep it running in the background:

[root@ncc1701 tmp]# mkdir /etc_mirror
[root@ncc1701 tmp]# nohup rsync -av /etc/ /etc_mirror/ &
[2] 56919
[root@ncc1701 tmp]# nohup: ignoring input and appending output to `nohup.out'
[root@ncc1701 tmp]#
[root@ncc1701 tmp]#
[2]-  Done                    nohup rsync -av /etc/ /etc_mirror/
[root@ncc1701 tmp]# du -sh /etc /etc_mirror
118M    /etc
118M    /etc_mirror
[root@ncc1701 tmp]# wc -l nohup.out
3565 nohup.out
[root@ncc1701 tmp]# rm nohup.out
[root@ncc1701 tmp]# rm -r /etc_mirror

Here I repeat the same process with the </dev/null addition:

[root@ncc1701 tmp]# mkdir /etc_mirror
[root@ncc1701 tmp]# nohup rsync -av /etc/ /etc_mirror/ </dev/null >/dev/null 2>&1 &
[2] 61837
[root@ncc1701 tmp]#
[root@ncc1701 tmp]#
[2]-  Done                    nohup rsync -av /etc/ /etc_mirror/ < /dev/null > /dev/null 2>&1
[root@ncc1701 tmp]# du -sh /etc /etc_mirror
118M    /etc
118M    /etc_mirror
[root@ncc1701 tmp]# wc -l nohup.out
wc: nohup.out: No such file or directory
[root@ncc1701 tmp]# rm -r /etc_mirror

Hooray.