Linux Double Ampersand

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

Linux Double Ampersand (&&)

The command shell interprets the && as the logical AND. When using this command, the second command will be executed only when the first one has been succcefully executed.


cd Desktop && cat jtp.txt 

Linux Double Ampersand1

Look at the above snapshot, both the commands are successfully executed.

Let's see an example of failed command.


rmdir sample && ls 

Linux Double Ampersand2

Look at the above snapshot, in first case "rmdir sample && ls" is successfully executed but in the second case directory 'sample' was already removed and hence second command 'ls' is failed and not executed.