---

Chaining Linux Commands Together

[ Thanks to Brandon for this link.
]

“What if you wanted to run a command and when it
finished, run another? Linux provides three ways to do this with a
slightly different end result. The semicolon (;), ampersand (&)
and the verticle pipe (|) all help the user “chain” commands
together.

“[user@localhost ~]$ apt-get update ; apt-get upgrade

“In this example we are using the semicolon (;) to separate
these two commands. Using a semicolon tells the shell, “once the
first command finishes, run the second one”. Once apt-get update
finishes, the system will then run it again using the upgrade
option.

“[user@localhost ~/project1]$ ./configure && make
&& make install

“This command is mainly used by developers, software package
maintainers and Linux power users. This chain of commands compiles
a program and installs it. What the double-ampersands are telling
the system is “wait for the first command to successfully complete.
If it does complete successfully, run the next command”.

Complete
Story

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends, & analysis