Warning: Undefined array key "HTTP_ACCEPT_LANGUAGE" in /home/u596154002/domains/usbusinessreviews.com/public_html/wp-includes/load.php on line 2057

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the rank-math domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home/u596154002/domains/usbusinessreviews.com/public_html/wp-includes/functions.php on line 6114
How to run multiple Linux commands at once - Best Business Review Site 2024

How to run multiple Linux commands at once

[ad_1]

man working on laptop

Getty Images/pixelfit

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.

Why? Because it’s more efficient.

Also: Elive 3.8.34 is a thing of beauty that any old-school Linux user would love

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. 

Also: The best Linux laptops

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. 

Also: How to choose the right Linux desktop distribution for you

With those things at the ready, let’s run some commands. I’ll first demonstrate the commands one at a time, so you can see how it all comes together.

Let’s first run a simple command. We’re going to create a new, empty, file. The command to be used is touch, and is run like this:

The above command creates a new file called zdnet_test.

The next command will add content to the file. That command looks something like this:

echo "Hello, ZDNET!" > zdnet_test

You can now view the contents of the new file with the command:

The output of the command will print “Hello, ZDNET!”.

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 content to the file, and view the file. The command for this will be:

touch zdnet_test && echo "Hello, ZDNET!" > zdnet_test && cat zdnet_test

As you can see, the && is the trick for combing commands together. It really is that simple.

Remember, I said you would need sudo privileges for some commands? Let’s say you want to update apt, run and upgrade, and then clean up your system by removing any unused dependencies. 

Also: How to get started with Git on Linux

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:

sudo apt-get update && sudo apt-get upgrade -y && sudo apt-get autoremove

Ah, but there’s another trick. Instead of typing sudo for each command, you could use this:

sudo sh -c 'apt-get update && apt-get upgrade && apt-get autoremove'

What we’ve done above is use the sh command interpreter with the -c option, such that everything in single quotes gets sudo privilege escalation.

Also: Ready to ditch Windows for Linux? This is the ideal distro for you

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. 



[ad_2]

Source link

slot gacor slot gacor togel macau slot hoki bandar togel slot dana slot mahjong link slot link slot777 slot gampang maxwin slot hoki slot mahjong slot maxwin slot mpo slot777 slot toto slot toto situs toto toto slot situs toto situs toto situs toto situs toto slot88 toto slot slot gacor thailand slot bet receh situs toto situs toto slot toto slot situs toto situs toto situs toto situs togel macau toto slot slot demo slot pulsa slot pragmatic situs toto deposit dana 10k surga slot toto slot link situs toto situs toto slot situs toto situs toto slot777 slot gacor situs toto slot slot pulsa 10k toto togel situs toto slot situs toto slot gacor terpercaya slot dana slot gacor pay4d agen sbobet kedai168 kedai168 deposit pulsa situs toto slot pulsa situs toto slot pulsa situs toto situs toto situs toto slot dana toto slot situs toto slot pulsa toto slot situs toto slot pulsa situs toto situs toto situs toto toto slot toto slot slot toto akun pro maxwin situs toto slot gacor maxwin slot gacor maxwin situs toto slot slot depo 10k toto slot toto slot situs toto situs toto toto slot toto slot toto slot toto togel slot toto togel situs toto situs toto toto slot slot gacor slot gacor slot gacor situs toto situs toto cytotec toto slot situs toto situs toto toto slot situs toto situs toto slot gacor maxwin slot gacor maxwin link slot 10k slot gacor maxwin slot gacor slot pulsa situs slot 10k slot 10k toto slot toto slot situs toto situs toto situs toto bandar togel 4d toto slot toto slot situs toto