Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run multiple Unix commands in one time?

Tags:

shell

unix

I'm still new to Unix. Is it possible to run multiple commands of Unix in one time? Such as write all those commands that I want to run in a file, then after I call that file, it will run all the commands inside that file? or is there any way(or better) which i do not know?

Thanks for giving all the comments and suggestions, I will appreciate it.

like image 977
keifer Avatar asked Jul 13 '11 02:07

keifer


People also ask

How do I run multiple commands in a single line in Unix?

Linux allows you to enter multiple commands at one time. The only requirement is that you separate the commands with a semicolon. Running the combination of commands creates the directory and moves the file in one line.

How do I run a Unix command multiple times?

Repeating a Command Using 'for' Loop You can use a 'for' loop to print a certain command multiple times. There are different variations of the 'for' loop, and we will explore all of them with the help of different bash scripts.

How do I run multiple shell commands in one line?

Windows. On Windows you can use a single ampersand (&) or two ampersands (&&) to separate multiple commands on one command line.


4 Answers

Short answer is, yes. The concept is known as shell scripting, or bash scripts (a common shell). In order to create a simple bash script, create a text file with this at the top:

#!/bin/bash

Then paste your commands inside of it, one to a line.

Save your file, usually with the .sh extension (but not required) and you can run it like:

sh foo.sh

Or you could change the permissions to make it executable:

chmod u+x foo.sh

Then run it like:

./foo.sh

Lots of resources available on this site and the web for more info, if needed.

like image 156
baraboom Avatar answered Oct 09 '22 19:10

baraboom


echo 'hello' && echo 'world'

Just separate your commands with &&

like image 34
adlawson Avatar answered Oct 09 '22 20:10

adlawson


We can run multiple commands in shell by using ; as separator between multiple commands

For example,

ant clean;ant

If we use && as separator then next command will be running if last command is successful.

like image 38
minhas23 Avatar answered Oct 09 '22 20:10

minhas23


you can also use a semicolon ';' and run multiple commands, like : $ls ; who

like image 34
Kernal Avatar answered Oct 09 '22 19:10

Kernal