How to Run Multiple Linux Commands at Once in Linux Terminal
[Essential Beginners Tip]
If you use Linux, you know how useful the command line can be for
working with files, installing software, and launching programs. But it can be
even more efficient if you run multiple commands at once.
Combining two or more commands on the command line is also known as “command
chaining”. We’ll show you different ways you can combine commands on the
command line.
Option One: The Semicolon (;) Operator
The semicolon (;) operator allows you to execute multiple commands in
succession, regardless of whether each previous command succeeds. For example,
open a Terminal window (Ctrl+Alt+T in Ubuntu and Linux Mint). Then, type the
following three commands on one line, separated by semicolons, and press Enter.
This will give you a listing of the current directory ( ls ), find out which
directory you’re currently in ( pwd ), and display your login name ( whoami )
all at once.
You don’t have to put spaces between the semicolons and the commands,
either. You can enter the three commands as ls;pwd;whoami . However, spaces
make the combined command more readable, which is especially useful if you’re
putting a combined command into a shell s
Option Two: The Logical AND Operator (&&)
If you want the second command to only run if the first command is
successful, separate the commands with the logical AND operator, which is two
ampersands ( && ). For example, we want to make a directory called
MyFolder and then change to that directory–provided it was successfully
created. So, we type the following on the command line and press Enter.
mkdir MyFolder && cd MyFolder
The folder was successfully created, so the cd command was executed and we
are now in the new folder.
We recommend using the logical AND operator rather than the semicolon
operator most of the time (;). This ensures that you don’t do anything
disastrous. For example, if you run a command to change to a directory and then
force remove everything in that directory recursively ( cd /some_directory ; rm
-Rf * ), you could end up ruining your system if the directory change didn’t
happen. Not that we recommend you run a command to unconditionally remove all
files in a directory at once.
linux execute multiple commands in sequence
how to execute multiple commands in unix shell script
run multiple commands in linux shell script
shell script to run multiple commands one after another
work with multiple linux terminal and basic commands
linux run multiple commands in parallel
linux run multiple commands from file
bash script run multiple commands in parallel
How do I combine two commands in Linux?
How do you run multiple commands at once?
How run multiple commands in Linux script?
How do you execute multiple scripts explain with an example?
Part of a video titled Shell Scripting Tutorial-61:
Executing Multiple Scripts - YouTube
How do you write multiple shell commands in one line?
How do I run multiple shell scripts after one?