14.6 C
Tuesday, November 30, 2021

How To Run Multiple Linux Commands at Once in Linux Terminal

Must read

In Linux, you need to run terminal commands simultaneously for installing and executing applications. If you’re a newbie in Linux, the chances are that you might be looking for methods to execute multiple commands at a time on your terminal shell. Especially, system administrators need to perform a bunch of commands like ifconfig and GRIP commands to handle loads. Linux allows users to get a newbie to professionals through commands. Knowing a handful of commands might make you different in the Linux community if you know how to use them and how to run multiple commands at once in the terminal on your Linux machine.

Multiple Linux Commands at Once in Linux Terminal

Power Linux users love the key combination of Ctrl+Alt+T to find files, install tools, and execute other tasks. Putting different symbols and signs in between two commands can help to perform multiple commands at a time on Linux. You can combine more than one similar command on Linux for better performance.

For instance, you can perform an apt update and upgrade command at a time by putting the & symbol in the command. In the entire post, we will see how to run multiple Linux commands at a time in the terminal shell.

1. Use the && Command

Executing combined commands on Linux with the & symbol is not a new thing. You can use the following format to combine two or more similar types of commands on Linux for powering up the system. The following command will update the system repository and then will upgrade the repo.

sudo apt update && sudo apt upgrade

Execute the following commands to make a new directory, browse the directory, and run the PWD command on the directory at a time through the && symbol.

mkdir new_dir && cd new_dir && pwd

make directory and PWD multiple command a t time on linux

2. Use the || Command

If you’re an experienced Linux user, if might already know that we can use a pipe (|) sign on the command for passing the output of the command. But, you can use a double-pipe (||) symbol in the command for making an OR condition in the command. The logical OR operator will decide what to do if the prior command is failed or false.

For instance, we can set logical OR operation in command for creating a new folder, browse that folder and print the directory details. If the mkdir command fails, the next part of the command will also fail.

mkdir new_dir1 || cd new_dir1 || pwd

use pipe commands together

3. Use the && and || Command

In the previous method, we have just seen the use of using double-pipe (||) and double and (&&) syntaxes on a terminal command. Here, we will use them together and run multiple Linux commands simultaneously. For instance, the following command will create a new directory named newdir and print the status that the directory is created using the Echo command.

$ cd newdir || mkdir newdir && echo "directory is created"

directory is created run multiple command on linux

4. Use the / Command

In Linux, power uses usually use the wget or cURL tool for downloading files. Then we can perform copying or moving that file to the desired directory. But, you can also combine two commands in a single line for downloading and moving the file inside the desired directory.

The following command will make a new directory inside the filesystem and move the downloaded file into that folder.

mkdir rpms/; mv foobar-1.3-2.i386.rpm rpms/

5. Use the ; Command

In different programming languages, the semicolon (;) symbol is used for ending a line in the program. In Linux bash, you can use the semicolon (;) symbol for adding more than one command in the same shell command to run multiple Linux commands.

For instance, here, we can browse a directory (ls command), print the directory path (through the PWD command), and see the current user details in the Linux system.

ls ; pwd ; whoami
$ ls ; pwd ; du ; whoami

use of semiclone for multiple commands

6. Use the / and ; Command

Till now, we have seen combining similar types of symbols for increasing work efficiency. Now, we will see how to add and combine two different types of symbols in a single command and run multiple Linux commands at a time. You can use the following command in the combination of / and  ;  for browsing a directory and removing the files. 

Please be careful before executing any rm -rf commands on Linux. It might delete important files with root access from your filesystem if you’re a newbie on Linux.

$ cd /my_directory ; rm -Rf *

7. Combination operator {}

The combination bracket operator functions for executing directory level commands. It can be used for executing a command and print the output status. For instance, you can run the following command given below to make a directory and then pull the Echo command to check the directory status on your Linux machine.

$ [ -d temp ] || { mkdir temp; echo temp directory is created now.; } && ls

Combination operator

Final Words

Mixing things up is great in Linux if you know what you’re doing. Executing several shell commands on the terminal shell definitely makes you a professional Linux user. In the entire post, I’ve illustrated several methods to run multiple Linux commands at a time in the shell.

If you’re good with shell scripting, you can also make your own customized commands to make things more professional. You can also open multiple tabs on the shell for running a bunch of commands at a time on your Linux system. If completing the prior command is not a prerequisite to the next command, it won’t cause any other issues.

I hope this post has been useful to you. Please share it with your friends and the Linux community if you find this post useful and informative. You can also write down your opinions regarding this post in the comment section.

Source link

- Advertisement -

More articles


Please enter your comment!
Please enter your name here

- Advertisement -

Latest article