I use the command $ nohup ... to start an application in the background so that I can close the terminal window afterwards.

Upon execution it creates the file ~/nohup.out.


orschiro@x230:~$ nohup /bin/bash -c "sleep 15 && python3 /home/orschiro/bin/show_state.py"
nohup: ignoring input and appending output to 'nohup.out'

How can I prevent nohup from creating nohup.out?

  • 2
    You might also consider byobu. :) – Andrea Lazzarotto Aug 31 '16 at 15:44
  • Thank you, @AndreaLazzarotto! Can you give me an example how to use it? – orschiro Aug 31 '16 at 17:28
  • 2
    Well, I suggest you have a look at the video here: byobu.co Basically, for what you want to do you just run byobu, start whatever you want, then press F6 and you are done. You can get back to it by running byobu again. – Andrea Lazzarotto Aug 31 '16 at 22:06
  • Excellent! You might want to add this as an official answer? – orschiro Sep 1 '16 at 5:57
  • Technically, my suggestion does not answer your question at all, it is just an alternative. :D – Andrea Lazzarotto Sep 1 '16 at 7:23

You may redirect the output anywhere you like, for example:

nohup /bin/bash -c "sleep 15 && python3 /home/orschiro/bin/show_state.py" >/dev/null 2>&1

redirection prevents the default output file nohup.out from being created. /dev/null is oblivion, so if you don't want the data at all, send it there.

In bash you can abbreviate >/dev/null 2>&1 to &>/dev/null

For programs I use often I make an alias (and add it to my .bashrc) for example

alias show_state='nohup /bin/bash -c "sleep 15 && python3 /home/orschiro/bin/show_state.py" >/dev/null 2>&1'

Now all I have to type is show_state

  • 2
    @orschiro: After a few years it won't be cryptic and you'll remember it ;) I suggest sticking with it, because aliasing it away means you won't gain that experience, and knowing how BASH redirection operators work off the top of your head is a crucial skill. – Lightness Races in Orbit Aug 31 '16 at 8:49
  • Wouldn't this be better off as a function? Something like show_state () { /bin/bash -c "$@" &>/dev/null }? (Warning: poor syntax and probably won't work! It's just an example!). One nitpick: why show_state when you're throwing away the output of nohup? – Ismael Miguel Aug 31 '16 at 10:31
  • I don't know what the script does @IsmaelMiguel but I assume it is an indicator with a tray icon, not to print "state" (whatever it is) to stdout. Sure, a function may well be more fun than an alias ^.^ – Zanna Aug 31 '16 at 10:48
  • Oh, I got it! Sorry, didn't see the name of the .py file. And yes, a function is more fun. I have this badly written function on a Debian desktop: shutup() { source "$@" >/dev/null 2>&1 & }. And it works. Maybe you could suggest something similar, but a lot better? – Ismael Miguel Aug 31 '16 at 11:43
  • I never knew that &> worked (and to my mind it looks like background plus stdout redirection). I always learned it as >&. Is it standard? – Random832 Aug 31 '16 at 14:04

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.