Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

bash run multiple commands in parallel

# Basic syntax:
# If you want to run a bunch of shell commands simultaneously, you can
# put them in a file followed by " &" and then bash the file, e.g.:
commands_to_run.txt # contains the following lines:
command 1 &
command 2 &
command 3 &

# Running the file with bash will cause all commands to be run in parallel
bash commands_to_run.txt

# Where this can be practical when you want to build up a set of similar 
#	shell commands to e.g. process a set of samples.
# Note,
#	- in Vim, you can type :%s/^/text to add before/ to add text at the
#		beginning of every line and :%s/$/text to add after/ to add text at the
#		end of every line.

# Example usage:
# Say you have a directory of files that you want to process in parallel with
# the same shell command. To do this, I'll often do the following:
# Send filenames to a file:
ls /directory/of/files > commands_to_run.txt

# Initial contents of file:
cat commands_to_run.txt
file1
file2
file3
file4

# Prepend and append relevant parts of the command:
vi commands_to_run.txt
:%s/^/beginning of command/
:%s/$/ &/

# Final contents of file:
cat commands_to_run.txt
beginning of command file1 &
beginning of command file2 &
beginning of command file3 &
beginning of command file4 &

# Run all commands in parallel
bash commands_to_run.txt
Comment

linux run two commands in parallel

Add the '&' symbol to the end of your command seperated by a space.
This will put the command in the background and allow bash to continue
running the script.

Example:
#!/bin/bash
command1 &
command2 &
command3
Comment

PREVIOUS NEXT
Code Example
Shell :: docker disable auto start 
Shell :: tr unix use 
Shell :: docker run always pull 
Shell :: how to delete all branches in git except master 
Shell :: wsl ubuntu update time 
Shell :: nano line number 
Shell :: show ip addr linux 
Shell :: haskell change version 
Shell :: create user with home directory ubuntu 
Shell :: bash for i in range 
Shell :: git amend commit message 
Shell :: dart 
Shell :: wsl2 vs virtualbox performance 
Shell :: bash split a word into characters 
Shell :: if command has output bash 
Shell :: linux command to clean up log files 
Shell :: git create tag and push 
Shell :: unable to install ta-lib 
Shell :: generating a new ssh key 
Shell :: gatsby transformer remark 
Shell :: push the project to github 
Shell :: install node package globally 
Shell :: install express globally 
Shell :: npm insall serve globally 
Shell :: port forward kubernetes 
Shell :: valgrind usage 
Shell :: powershell convert to json 
Shell :: install geopandas in jupyter notebook 
Shell :: ignore file git 
Shell :: find logs in kubernetes pods 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =