TECHIES WORLD

For Techs.... Techniques.... Technologies....

BashLinux

How to run multiple commands together in Linux

This article explains the method to run multiple Linux commands in together.

Method1: Using semicolon (;) operator

The semicolon (;) operator execute multiple commands together without considering the previous command success or not.

command1; command2

For example,

pwd ; date

Here both the command will be executed without any issues.

Method2: Logical AND (&&) operator

The logical AND (&&) operator execute multiple commands together, but the execution happens only if the previous command is successful.

command1 && command2

For example,

cd /home/test && mkdir newfolder

Here the second command executes only if the first command is successful.

Method3: Using logical OR (||) operator

The logical OR (||) operator execute multiple commands together, but the execution happens only if the previous command is unsuccessful.

command1 || command2

For example,

[ -d ~/test ] || mkdir ~/test

Here the second command executes only if the first command is unsuccessful.

That's all…