I want to send only first command to run in background. How can I do that?
For example for this commands

sudo apt-get update & && apt-get upgrade

My first command must run before second command like above and I don't want to run second command as first. Then above example is really good example since I have to run update command before upgrade.

But it give error(for my real command too):

bash: syntax error near unexpected token `&&'
  • see if the edit works for you – Rinzwind Oct 19 '14 at 10:11

Both in background:

~$ (sleep 1 &) && (sleep 2 &)

1st in background

~$ (sleep 1 &) && (sleep 2)

wont work with apt-get though.

edit: found it.

 sudo bash -c 'apt-get update >/dev/null 2>&1 & disown' && sudo apt-get upgrade


sudo bash -c 'apt-get update >/dev/null 2>&1 & disown' && sudo apt-get upgrade
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... The following packages were automatically installed and are no longer required:
  gtk2-engines-pixbuf libcrypt-blowfish-perl libcrypt-cbc-perl
  libcrypt-rijndael-perl libexpect-perl libgnome2-gconf-perl
  libgtk2-ex-simple-list-perl libgtk2-gladexml-perl libgtk2-unique-perl
  libio-stty-perl libkeybinder0 libnet-arp-perl libnet-pcap-perl
  libnet-proxy-perl libossp-uuid-perl libossp-uuid16 libunique-1.0-0
  libxml-parser-perl python-keybinder
Use 'apt-get autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

and the update is still running:

~$ ps -ef|grep apt-get
root      6102  1519  1 12:11 pts/0    00:00:00 apt-get update

It will break the sequence though: the upgrade will finish before the update.

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