Why you can trust ZDNET
:ZDNET independently tests and researches products to bring you our best recommendations and advice. When you buy through our links, we may earn a commission.Our process
'ZDNET Recommends': What exactly does it mean?
ZDNET's recommendations are based on many hours of testing, research, and comparison shopping. We gather data from the best available sources, including vendor and retailer listings as well as other relevant and independent reviews sites. And we pore over customer reviews to find out what matters to real people who already own and use the products and services we’re assessing.
When you click through from our site to a retailer and buy a product or service, we may earn affiliate commissions. This helps support our work, but does not affect what we cover or how, and it does not affect the price you pay. Neither ZDNET nor the author are compensated for these independent reviews. Indeed, we follow strict guidelines that ensure our editorial content is never influenced by advertisers.
ZDNET's editorial team writes on behalf of you, our reader. Our goal is to deliver the most accurate information and the most knowledgeable advice possible in order to help you make smarter buying decisions on tech gear and a wide array of products and services. Our editors thoroughly review and fact-check every article to ensure that our content meets the highest standards. If we have made an error or published misleading information, we will correct or clarify the article. If you see inaccuracies in our content, please report the mistake via this form.
When you finally start working with the Linux command line, you'll find numerous ways to make the process more efficient. By running two or more commands at once, you'll not have to wait until one finishes to start the next.
These days, the majority of my time spent on Linux is via GUI applications. That doesn't mean I can completely avoid the command line. Why? Partially because I also work with servers. But, every so often, I'll opt to use the command line on the desktop. For instance, when I need to run upgrades on a system, I'll open a terminal window and walk through the process manually.
With an Ubuntu-based system, that process often requires running a few commands. For that, I have two options: I can run a single command, wait for it to complete, run the next command, wait for it to complete, run the next command…you get the picture.
However, there's also my second option -- a much easier method, which allows you to run all of those commands from a single, typed line.
Now, before we continue, let me explain a few things. First, the commands you combine together do not run simultaneously. Instead, the first command will run and, when the first command completes, the second command will run (and so on).
The next thing to keep in mind is that should the first command fail, the next commands will not run. Finally, this approach is different from piping commands (which I'll talk about in a later article), where the output of the first command serves as the input for the second command.
What we're doing here is simply running multiple commands from a single typed line. These commands could be completely different. For example, you could list the contents of a directory, update apt, and then list the usage of your drives with the dh command. That's part of the beauty of this feature -- it's flexibility. You can also run a mixture of commands that require sudo privileges and commands that don't.
So, how is this done? It's very simple. Let me show you how.
How to combine Linux commands
What you'll need: The only thing you'll need for this demonstration is a running instance of Linux. It doesn't matter what distribution you use, as this process is the same on all versions. Remember, to run certain admin-level commands, you'll need a user with sudo privileges.
The three individual commands for that are sudo apt-get update, sudo apt-get upgrade, and sudo apt-get autoremove. To combine them together, all three commands will require sudo privileges, so the command looks like this:
And that's all there is to it. Although this approach won't save you a ton of time, it will prevent you from having to wait until one command completes before running the next. This can be very helpful when running a group of commands, each of which takes considerable time (such as a backup).
Instead of having to wait for one command to complete before running the next, run them all at once, and walk away to take care of other business. That's efficient.