Synthird's blog

&& and || in the Linux terminal

Double ampersand (&&)

command-one && command-two

command-two will run if command-one was a success.

Example 1

This command:

echo This text will be displayed && echo And this too

Will show this in the terminal:

This text will be displayed
And this too

Example 2

This command:

terminal-commands-are-fun && echo This will not display

Will give only a command not found error:

terminal-commands-are-fun: command not found

Double pipe (||)

command-one || command-two

command-two will run if command-one was not successful.

Example 1

This command:

echo This text will display || echo This will not

Will show in only the words "This text will display" in the terminal:

This text will display

Example 2

The command:

terminal-commands-are-fun || echo This will display

Will show a command not found error and the text "This will display" in the terminal:

terminal-commands-are-fun: command not found
This will display