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

3

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?

    
asked by anonymous 25.08.2015 / 15:32

1 answer

7

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 .

    
25.08.2015 / 15:51