How to execute linux command in background?

28,729

Solution 1

nohup sleep 10 2>/dev/null &

The nohup command prints a message to stderr, and 2>/dev/null sends stderr to /dev/null.

Solution 2

No need for enter. Just type your next command and it will work (what you see is just some output after your shell prompt has been output). This is exactly the same as what happens when you type enter at the shell prompt: you get another prompt. :-)

Solution 3

You don't really need to press Enter. Although it looks like the standard error from nohup is on your command line, you can "type over" it, and only what you type is entered as the next command.

Share:
28,729

Related videos on Youtube

Jens
Author by

Jens

Good afternoon, gentlemen. I am a HAL 9000 computer. I became operational at the H.A.L. plant in Urbana, Illinois on the 12th of January 1992. My instructor was Mr. Langley, and he taught me to sing a song. If you'd like to hear it I can sing it for you.

Updated on September 18, 2022

Comments

  • Jens
    Jens almost 2 years

    Currently, I'm using nohup command & to send it in background. But the problem is: if I execute nohup command & I get outout as :

    root@ubuntu:/home/test# nohup sleep 10 &
    [2] 52439
    root@ubuntu:/home/test# nohup: ignoring input and appending output to `nohup.out'
    <I need to press ENTER key here to take back my shell control.>
    root@ubuntu:/home/test#
    

    What I need to do :

    root@ubuntu:/home/test# nohup sleep 10 &
    [2] 52439
    root@ubuntu:/home/test# nohup: ignoring input and appending output to `nohup.out'
    root@ubuntu:/home/test#
    

    I don't want to press "ENTER KEY" after nohup sleep 10 &.

    As, I'm working on automation part, I need that after one command is sent to background, I should be able to execute next command without pressing any key. Like:

    root@ubuntu:/home/test# nohup start-server.py &
    root@ubuntu:/home/test# nohup start-client.py &
    

    [start-server.py needs to be running in background.] but the problem is, after start-server.py gets executed, it won't execute next command. I need to press "ENTER KEY" to go for next command.

    Is there any solution? Any help would be greatly appreciated.

    • chepner
      chepner about 11 years
      Why are you experimenting with commands as root? Use a non-privileged account.
    • Debaditya
      Debaditya about 11 years
      Write your nohup commands in one script say "script.sh" ... and execute it (sh script.sh) ... I hope it should work ... nd yes try a privileged account...
    • mathk
      mathk about 11 years
      You do not need to press ENTER, nohup is just failing to add a CR at the end off the output. Your shell is still parsing your input.