What is the difference between & e && in SHELL?

Posted on

Question :

I’m using the Ubuntu Terminal.

I learned a certain command to be able to free memory, which is:

free & sync

In another case, I learned something like

nohup &&

After all, how are these two operators called ( & and && ) and what are the differences between them?

    

Answer :

The & (Ampersand) operator is used to put the previous command in background and, if there is a subsequent command, it will run regardless of the result of the previous command:

free & sync

When this operator is used at the end of a command on a terminal in Linux, it means that you want to execute that command and release the terminal for new commands without waiting for the result of the last command:

wget http://pt.stackoverflow.com &

The && (AND) operator is used so that the next command is executed only if the previous command has been successfully executed ( exist status equal to 1):

mkdir pasta && cd pasta

More details can be found here .

    

Leave a Reply

Your email address will not be published. Required fields are marked *