PDA

View Full Version : [all variants] How To Combine Commands in Linux



vokevybez
July 5th, 2012, 07:05 PM
How do i combine commands like for example if i wanted to combine
cd /home and
cd /media consecutively. Is there a specific symbol or something of the sort?

sandyd
July 5th, 2012, 07:13 PM
How do i combine commands like for example if i wanted to combine
cd /home and
cd /media consecutively. Is there a specific symbol or something of the sort?

There is a syntax to
a) Run commands one after the other (only if the command before it is successful)
b) Run commands all at once.

a) uses "&&"

For example,


cd /root && touch test && touch test2
That would run one command after the other

b) uses "&"

For example


cd /root & touch test & touch test2
That would run all of them at once, and would probably not be advisable.

vokevybez
July 5th, 2012, 07:18 PM
Thanks a lot this will help with my bash tutorial :p

Pinoy Tux
July 6th, 2012, 08:38 AM
c) Run the commands sequentially, regardless if the previous command in the chain was successful or not: use the semicolon.


cd /home ; ls -l ; cd /root ; ls -l

andrew.46
July 6th, 2012, 08:59 AM
Most of the information has been presented here for you but the gruesome details can be seen in the bash man pages under 'Lists'.

vokevybez
July 6th, 2012, 02:56 PM
Most of the information has been presented here for you but the gruesome details can be seen in the bash man pages under 'Lists'.
thank you for your input the information covered is very comprehensive

SeijiSensei
July 6th, 2012, 03:36 PM
Most of the information has been presented here for you but the gruesome details can be seen in the bash man pages under 'Lists'.

Real men read the man pages because they like learning about all those gruesome details! I'll admit the bash man page is a bit overwhelming though. The "grep" man page isn't far behind.

andrew.46
July 7th, 2012, 05:11 AM
Another well written man page is the 'find' page, pity they are all not as well done :).