No one seems to be explaining why you would use each one, given your actual examples. I'll take a stab at it:
killall Finder; killall SystemUIServer
A command like killall
can take some time to execute. By using the semicolon, you can give both commands at once and then do something else while you wait. That way you don't have to wait twice (once for each command).
cd ~/Desktop/ && rm Caches
You want to remove the directory ~/Desktop/Caches
and end up in the directory ~/Desktop
. What you do not want to do is to remove the directory Caches from the current directory (before you change it). So you use &&
to check that the directory change was successful before you do your remove command.
man grep | man cat
This makes no sense to me. The man
command does not process input, so piping things to it won't do anything. Perhaps you meant
man grep || man cat
That would try to find the man page for grep
and then if it couldn't, would show the man page for cat
. Or possibly you meant
man grep | cat
That would use cat
to display the man page rather than the pager (normally less
). The |
redirects the output from man
to the command cat
(which just dumps everything to screen). This can be useful in a GUI where you can use the scroll bar to go back and forth in the file rather than using the keyboard commands in less.
Note: if you want to know what ;
&&
|
||
do in the more general cases, then I'd suggest looking at jimmij's answer. I'm just trying to explain what's happening in the examples from the question.
man bash
? – Martin Schröder Oct 06 '14 at 12:02&&
is explained in the paragraph containing the second match. – Daniel Beck Oct 06 '14 at 16:10bash
as is the other. I also find it strange that a question with an answer garnering 34 votes - as @jimmij's has - should be so easily dismissed. I noted my own disapproval in this answer to terdon's meta question and - for what little it is likely to be worth - I have voted to reopen this question. – mikeserv Oct 06 '14 at 21:42