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?
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.
Sign up to join this communityYes, 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
&&
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.
Aug 20, 2013 at 14:42
This illustrates more:
A ; B – Run A and then B, regardless of the success or failure of A
A && B – Run B only if A succeeded
A || B – Run B only if A failed
source :https://www.howtogeek.com/269509/how-to-run-two-or-more-terminal-commands-at-once-in-linux/
;
or&&
to execute multiple commands in one line" is a lot better, has more research and would likely have attracted a great many upvotes.