How Can We Use Operators In Linux and Unix CLI?


A token that performs a control function. It is a newline or one of the following:

Ampersand ( & ) 

When a line ends with ampersand &, the shell will not wait for the command to finish. You will get your shell prompt back, and the command is executed in background.

for example :


Semicolon (;)

You can put two or more commands on the same line separated by a Semicolon ; . Both series will be executed sequentially with the shell waiting for each command to finish before starting the next.

For example :


Double Ampersand (&&)

When using && the second command is executed only if the first one succeeds.

For example:


Double vertical bar (||)

The || represents a logical OR. The second command is executed only when the first command is fail.

For example :


Combine && with ||

You can use this logical AND and logical OR to write an if-then-else structure on the command line.

For example:


Pound sign (#)

Everything written after a pound sign (#) is ignored by the shell. This is useful to write a shell comment, but has no influence on the command execution or shell expansion.

For example:


Escaping special characters

The backslash character enables the use of control characters, but without the shell interpreting it, this is called escaping characters.

For example:


End of line backslash

Lines ending in a backslash are continued on the next line. The shell does not interpret the newline character and will wait on shell expansion and execution of the command line until a newline without backslash is encountered.

For example :


Dollar Question mark ($?)

The exit code of the previous command is stored in the shell variable $?. Actually $? is a shell parameter and not a variable. This parameter is used to check the last executed command status. If the value returned by $? is 0, that was a success one otherwise that was a failed one.


0 – Represents a successful command.
1 or any-other non zero – Represents a failed output.

You can use the above operators in your server administration’s works or script that running on client 🙂

make me happy with your comments if you have any questions 🙂