0

I was wondering how to execute all the commands present in a text file at the same time in Linux. Brief background- I have created a text file with content as below,

 nohup execute_command1
 nohup execute_command2
 .
 .
 .
 nohup execute_command30

And now I want to execute all the commands present in the text file at the same time in Linux server. How do I do that?

Christian Fritz
  • 20,641
  • 3
  • 42
  • 71
Pradhan
  • 1
  • 1
  • 3
    Here you found the answers: [Run multiple commands and kill them as one in bash](https://unix.stackexchange.com/questions/204480/run-multiple-commands-and-kill-them-as-one-in-bash) [Running multiple commands in one line in shell](https://stackoverflow.com/questions/5130847/running-multiple-commands-in-one-line-in-shell) [How can I run multiple commands which have & in one command line?](https://askubuntu.com/questions/990423/how-can-i-run-multiple-commands-which-have-in-one-command-line) – Z0OM Apr 18 '22 at 16:14

2 Answers2

2

Put & at the end of each line.

Bib
  • 922
  • 1
  • 5
  • 10
0

You have already created a file, you could turn this into a script by adding a hash bang to the top of the file (for bash use #!/usr/bin/env bash )

Then you can make that script executable by running chmod +x filename Then run the script with ./filename

This will run each of your commands in order, to run them all at the same time put & at the end of each command (as mentioned by @bib).

You file should look like

#!/usr/bin/env bash
command1 options &
command2 options &
....
commandn options &

All of the processed will be running in the background and the script will end. If these are long running processes you will need to find and kill the process once you are finished with it.