Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have the following commands.

cd import
zcat urls1.sql.gz | mysql -u root -p urls
cd /var/www/project1/
nano 1.php

As of now I'm executing it one by one.

Is there a way to combine those commands in one line?

share|improve this question
2  
Did you do any research for this question? –  don.joey Aug 20 '13 at 14:33
    
That was not my question. It is just that half a minute of googling would have given you the answer. Hence, I was wondering what you had already found, if anything. –  don.joey Aug 20 '13 at 15:04
    
What makes you think I downvoted your question? I will neglect your anger. As a side-note, the question "which one is better: using ; or && to execute multiple commands in one line" is a lot better, has more research and would likely have attracted a great many upvotes. –  don.joey Aug 20 '13 at 16:25
    
There is a more generic variant of this question available at askubuntu.com/questions/334994/…. It deal with exactly the question I mention in the previous comment. –  don.joey Aug 20 '13 at 16:42
    
@Private I really apologize about my previous comment. I thought you were the one who downvoted my question. As for your latest comment.. Yes if I posted question like your title, I might have attracted great many upvotes. But I’m not here to gain upvotes. Am I? I just needed a better solution. –  Giri Aug 20 '13 at 16:42

1 Answer 1

up vote 5 down vote accepted

Yes, separate with a semi-colon like so:

dir; ls -l

Most lanugauges/shells use the semi-colon to signify the end of a command and to start new while evaluating from left to right.

Or as @RobieBasak recommends, use && instead of ; to guard against coding accidents.

dir && ls -l
share|improve this answer
8  
It's a good idea to use && instead of ;. This ensures that subsequent commands are only executed if previous commands have not failed. This avoids some awkward consequences. For example: cd /somewhere_else; rm -Rf * could do something disastrous if /somewhere_else doesn't exist or you mis-spell it; cd /somewhere_else && rm -Rf * protects you from this. –  Robie Basak Aug 20 '13 at 14:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.