Chaining Linux Commands Together
Feb 03, 2009, 01:32 (0 Talkback[s])
[ 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
Related Stories:
- 10 Mistakes New Linux Administrators Make(Dec 01, 2008)
- Tip: Using find Command in Linux(Nov 19, 2008)
- Tips and Tricks for Working on the Command Line(Nov 12, 2008)
- NetCat Tutorial for Linux & Windows(Sep 22, 2008)
- Bash Shell: Take Control of PS1, PS2, PS3, PS4 and PROMPT_COMMAND(Sep 12, 2008)
- The Joys of xargs(Aug 29, 2008)
- Review: Bash Cookbook(Aug 13, 2008)
- 15 Examples To Master Linux Command Line History(Aug 12, 2008)