I'm running this command:

$ nohup command > foo.out 2> foo.err < /dev/null &

My problem is that even though nohup makes my command run in the background, it prints out something like this to my terminal:

[1] 27918

How do I make it not output the job number? I just want it to do it in the background without telling me anything. On Mac OS X, that's exactly what happens, so I'm a little annoyed that it works differently on Ubuntu...

Thanks for the help!

  • 2
    The [1] 27918 is coming from the & not the nohup – Majenko Mar 1 '11 at 8:50
  • Thanks Matt, that did it. Now how do I close this question... – hora Mar 1 '11 at 8:53
  • The way to do that is mark an answer as accepted using the checkmark next to it. – Paused until further notice. Mar 1 '11 at 10:06
  • See superuser.com/faq section "How do I ask questions" – user1686 Mar 1 '11 at 10:10

Job information is displayed by your shell, not nohup.

You could try this alternative:


( spawns a subshell, which handles job control differently.

(I have nh() { ("$@" &); } in my ~/.bashrc, so I can type nh command to do the same thing.)

Another, different way:

setsid yourcommand

Edit: It seems that (setsid yourcommand &) is the best combination, since it detaches from the tty and works equally in interactive and script modes.

| improve this answer | |
  • (command &) worked for me where I was having ioctl error with nohup. – Shahzada Hatim May 10 '12 at 12:22

The [1] 27918 is coming from the & not the nohup.

Put the command you want to run in the background inside a script file:

/path/to/command & >/dev/null 2>/dev/null

and then call that with nohup

nohup sh /path/to/my/script > foo.out 2> foo.err < /dev/null

The output of & is then redirected to /dev/null inside the script.

| improve this answer | |
  • & is only a command terminator, it doesn't output anything and you cannot redirect it. In interactive mode, the job line is printed by the shell; in non-interactive (including scripts), it remains quiet. Your inner redirects apply to output of the command itself, and I do not think the outer redirects will override them. – user1686 Mar 1 '11 at 9:05

Just as the one above mentioned (Thanks, by the way).

Within a script named test.ksh:

./test2.ksh >/dev/null
nohup ksh test2.ksh < /dev/null
echo  "whatever"

Where test2.ksh is another script (or may be a command):

for ((i=2; i<=$max; ++i )) ; do
    echo -e "\n Hello world "

Then, run:

~> ksh test.ksh

and the output is:

nohup: appending output to `nohup.out'

It worked for me

If you keep the & in the redirection

./test2.ksh & >/dev/null

It will print both in the tty and the file .out

| 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.