HOWTO: String Commands Together Using the Semi-Colon
I had to make sure that I put the ‘using the semi-colon’ part in the title because there are a variety of ways to string commands together in GNU/Linux. Some are more powerful than others (like using the pipe | symbol) and some are just convenient.
The semi-colon operator is more of a convenience than anything really powerful. The semi-colon doesn’t perform any function, it just takes the place of hitting the enter key between commands.
Try this:
mkdir temp; cd temp; ls -all
As you can likely figure out, this will make a directory named temp in the current directory, change to the new directory and then list its contents (yes, it’s new so it will be empty).
You can also run applications and carry on with instructions as the terminate. For example:
nano foo; cd /
Assuming you have the nano editor installed, this will fire it up with the foo file loaded (or blank if you have no foo file). Once you’re done editing and save or otherwise exit nano, you will be taken to the / root directory.
These are two pretty lame-O examples, but they get the point across. Stringing commands together is likely more useful in scripting than in every day life. If you have a decent imagination, it’s easy to see how you can use the semi-colon operator in conjunction with command substitution to build a pretty powerful sequence of events.
Related Stories
POSTED IN: How To
1 opinion for HOWTO: String Commands Together Using the Semi-Colon
Jack
Dec 9, 2007 at 6:00 pm
This was exactly what I wanted, no extra stuff except what I wanted
Thanks
Jack
Have an opinion? Leave a comment: