These days, about 50% of my time is spent wading through GUI applications on Linux. Of course, I also work with servers, so I get to work with the command line as well. From time to time, I’ll opt to use the command line on the desktop. For example, when I need to run an upgrade on a system, I’ll open a terminal window and go through the process manually.
With an Ubuntu-based system, that process often requires running a few commands. For this, I have two options: I can run a command, wait for it to complete, run the next command, wait for it to complete, run the next command… you get the picture Will get
Also: How to Install Ubuntu Linux (It’s Easy!)
However, I have another option as well – and it’s a much simpler method, which allows you to run all those commands from a single typed line.
Now, before we go any further, let me clear a few things up. First, the commands you link together don’t run together. 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 if the first command fails, the next command will not run. Finally, this approach differs 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.
Too: best linux laptop
What we are doing here is simply running multiple commands from a single typed line. These commands can be completely different. For example, you can list the contents of a directory, update apt, and then list your drive usage. DH’s Permission. That’s part of the beauty of this facility – its flexibility. You can also run a mixture of commands that require sudo privileges and commands that don’t.
So, how is it done? It’s very simple. let me tell you how.
how to run multiple linux commands at once
what you’ll need: The only thing you’ll need for this demonstration is a running instance of Linux. It doesn’t matter which distribution you use, as the process is the same on all versions. Remember, to run some administrator-level commands, you’ll need a user with sudo privileges.
Also: How to Choose the Right Linux Desktop Distribution for You
With those things ready, let’s run a few commands. I’ll demonstrate the commands one by one first, so you can see how they all come together.
Let’s run a simple command first. We’re going to create a new, empty file. The command used is touch , and is run as:
The above command creates a new file named zdnet_test.
The next command will add the content to the file. That command looks something like this:
echo "Hello, ZDNET!" > zdnet_test
Now you can view the contents of the new file with the command:
The output of the command “Hello, ZDNET!” Will print
Now that you know the command sequence (and what it does), let’s combine them all together, such that we’ll create the file, add the content to the file, and view the file. The command for this would be:
touch zdnet_test && echo "Hello, ZDNET!" > zdnet_test && cat zdnet_test
As you can see, && does the trick to link the commands together. It really is that simple.
Remember I said you’ll need sudo privileges for some commands? Let’s say you want to update, run and upgrade apt, and then clean up your system by removing any unused dependencies.
Also: How to Get Started with Git on Linux
There are three separate commands for this: 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:
sudo apt-get update && sudo apt-get upgrade -y && sudo apt-get autoremove
Ah, but there’s one more trick. Instead of typing sudo for each command, you can use:
sudo sh -c 'apt-get update && apt-get upgrade && apt-get autoremove'
what we did above is use this Mister The command interpreter with the -c option, as such, everything in single quotes gets sudo privilege escalation.
Too: Ready to give up Windows for Linux? this is the ideal distro for you
And that’s all. Although this approach won’t save you a lot of time, it will prevent you from having to wait for one command to complete before running the next. This can be very helpful when running a bunch of commands, each of which takes a long time (such as a backup).
Instead of waiting for one command to complete before running the next, run them all at once, and go on to take care of other business. That is effective.











