Per default, nohup writes stdout to nohup.out and dismisses stderr. I would like to have it the other way around:

write stderr to a file and dismiss stdout.


You can do it like this:

nohup command 2>&1 >/dev/null &

Because the first redirect is from STDERR to current handler of STDOUT it write to nohup.out. Then STDOUT is redirected to NULL

  • what about redirecting stderr to a file?
    – kerner1000
    Jan 28 '19 at 16:25
  • Let edit the answer (with usual &) Jan 28 '19 at 16:28

Just redirect standard error to the file you want:

$ ls
$ cat test.sh
echo "out"
echo "error" 1>&2
$ ./test.sh
$ nohup ./test.sh < /dev/null > /dev/null 2> err.out
$ ls
err.out  test.sh
$ cat err.out

From the manual:

If standard input is a terminal, redirect it from an unreadable file. 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.

Given that it is silent if stderr is redirected, it stands to reason that it would behave normally, and, as shown above, it does.

  • this does not seem to work, I still see INFO messages in the err.out.
    – kerner1000
    Jan 28 '19 at 16:26
  • 1
    Unsure why; I just made my test more extensive (see edit) and it behaves as I expect and descrive.
    – DopeGhoti
    Jan 28 '19 at 16:30
  • maybe it is because the command is java -jar ...
    – kerner1000
    Jan 28 '19 at 16:37

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.