Bash: Put a job in the background and then tail the log

6,587

Solution 1

Just drop the semicolon:

# foo param1 param2 >> run.out & tail -f run.out

Solution 2

You need to put the backgrounded command in ()'s.

(ls -R / >>/tmp/list & ); tail -f /tmp/list

Sadly, this really backgrounds it. You won't be able to us %1 to get to its PID.

Share:
6,587
Alex
Author by

Alex

I'm a Distinguished Engineer at Robinhood. I used to be the Tech Lead of Developer Productivity at Stripe where I built Sorbet. Before that I was the CTO and cofounder at Trimian. Before that I was a Software Engineer at Facebook on HHVM and the Open Graph. Before that I was the Tech Lead for Yahoo! SearchMonkey. See my homepage for more.

Updated on September 17, 2022

Comments

  • Alex
    Alex over 1 year

    How do you make the escaping work so that the & is actually running the first command in the background?

    # foo param1 param2 >> run.out &; tail -f run.out
    
  • Teddy
    Teddy over 14 years
    It helps to think of the ampersand as a variant of the semicolon, which it is, really.