If I wanted to run two separate commands on one line, I could do this:
cd /home; ls -al
or this:
cd /home && ls -al
And I get the same results. However, what is going on in the background with these two methods? What is the functional difference between them?
Best Answer
The
;
just separates one command from another. The&&
says only run the following command if the previous was successfulThis will
cd /home
and even if thecd
command fails (/home
doesn't exist, you don't have permission to traverse it, etc.), it will runls -al
.This will only run the
ls -al
if thecd /home
was successful.