143

I frequently use the program nohup so that my processes are immune to hangups. So if I want to make the program program immune to hangups, I use the command

nohup program &

where & puts the process in the background.

When starting, nohup gives me the message:

nohup: appending output to `nohup.out'

Is there any way to send the output to a file other than nohup.out? Often I want to run many processes in the same directory using nohup, but if I do this, all the output gets lumped together in a single nohup.out file.

The manual page (for example, here) does not seem to have an option for specifying the log file. Can you please confirm this? Also, do you have any thoughts of how I can work around this problem?

163

GNU coreutils nohup man page indicates that you can use normal redirection:

If standard input is a terminal, redirect it from /dev/null. If standard output is a terminal, append output to 'nohup.out' if possible, '$HOME/nohup.out' otherwise. If standard error is a terminal, redirect it to standard output. To save output to FILE, use 'nohup COMMAND > FILE'.

Edit: I didn't read your link at first; you may have a different version of nohup, although this section suggests that you can still use normal redirection:

 nohup.out          The output file of the nohup execution if
                    standard  output is a terminal and if the
                    current directory is writable.

You can redirect standard output and standard error to different files:

nohup myprogram > myprogram.out 2> myprogram.err

or to the same file:

nohup myprogram > myprogram.out 2>&1
| improve this answer | |
  • 4
    And this isn't specific to GNU utilities, the behavior is specified by POSIX. – Gilles 'SO- stop being evil' Aug 20 '12 at 22:33
  • 5
    It doesn't seem to work. It redirect the output of nohup command rather the output of myprogram. – Kris Mar 7 '18 at 16:21
  • 3
    @Kris Redirection should take place before the trailing & character – yunzen Nov 7 '18 at 8:29
12

Adding Jim comment as an answer here for more visibility.

use nohup program > program.out & to write the output to program.out instead of nohup.out

| improve this answer | |
1

nohup program &> program.out &

or

nohup program &> program.out if you don't want to run the job in the background. I use this when I'm running multiple jobs at once and I want to limit it.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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