parallel - build and execute shell command lines from standard input in parallel
parallel [options] [command [arguments]] [< list_of_arguments]
GNU parallel is a shell tool for executing jobs in parallel using one or more machines. A job is typically a single command or a small script that has to be run for each of the lines in the input. The typical input is a list of files, a list of hosts, a list of users, a list of URLs, or a list of tables.
If you use xargs today you will find GNU parallel very easy to use as GNU parallel is written to have the same options as xargs. If you write loops in shell, you will find GNU parallel may be able to replace most of the loops and make them run faster by running several jobs in parallel. If you use ppss or pexec you will find GNU parallel will often make the command easier to read.
GNU parallel makes sure output from the commands is the same output as you would get had you run the commands sequentially. This makes it possible to use output from GNU parallel as input for other programs.
For each line of input GNU parallel will execute command with the line as arguments. If no command is given, the line of input is executed. Several lines will be run in parallel. GNU parallel can often be used as a substitute for xargs or cat | sh.
Command to execute. If command or the following arguments contain {} every instance will be substituted with the input line. Setting a command also invokes -f.
If command is given, GNU parallel will behave similar to xargs. If command is not given GNU parallel will behave similar to cat | sh.
Input line. This is the default replacement string and will normally be used for putting the argument in the command line. It can be changed with -I.
Input line without extension. This is a specialized replacement string with the extension removed. If the input line contains . after the last / the last . till the end of the string will be removed and {.} will be replaced with the remaining. E.g. foo.jpg becomes foo, subdir/foo.jpg becomes subdir/foo, sub.dir/foo.jpg becomes sub.dir/foo, sub.dir/bar remains sub.dir/bar. If the input line does not contain . it will remain unchanged.
{.} can be used the same places as {}. The replacement string {.} can be changed with -U.
Use NUL as delimiter. Normally input lines will end in \n (newline). If they end in \0 (NUL), then use this option. It is useful for processing arguments that may contain \n (newline).
Read items from the file input-file instead of standard input. If you use this option, stdin is given to the first process run. Otherwise, stdin is redirected from /dev/null.
Remove transferred files. --cleanup will remove the transferred files on the remote server after processing is done.
find log -name '*gz' | parallel \ --sshlogin server.example.com --transfer --return {.}.bz2 \ --cleanup "zcat {} | bzip -9 >{.}.bz2"
With --transfer the file transferred to the remote server will be removed on the remote server. Directories created will not be removed - even if they are empty.
With --return the file transferred from the remote server will be removed on the remote server. Directories created will not be removed - even if they are empty.
--cleanup is ignored when not used with --transfer or --return.
Line is a command. The input line contains more than one argument or the input line needs to be evaluated by the shell. This is the default if command is not set. Can be reversed with -f.
Input items are terminated by the specified character. Quotes and backslash are not special; every character in the input is taken literally. Disables the end-of-file string, which is treated like any other argument. This can be used when the input consists of simply newline-separated items, although it is almost always better to design your program to use --null where this is possible. The specified delimiter may be a single character, a C-style character escape such as \n, or an octal or hexadecimal escape code. Octal and hexadecimal escape codes are understood as for the printf command. Multibyte characters are not supported.
Set the end of file string to eof-str. If the end of file string occurs as a line of input, the rest of the input is ignored. If neither -E nor -e is used, no end of file string is used.
This option is a synonym for the -E option. Use -E instead, because it is POSIX compliant for xargs while this option is not. If eof-str is omitted, there is no end of file string. If neither -E nor -e is used, no end of file string is used.
Line is a filename. The input line contains a filename that will be quoted so it is not evaluated by the shell. This is the default if command is set. Can be reversed with -c.
Group output. Output from each jobs is grouped together and is only printed when the command is finished. STDERR first followed by STDOUT. -g is the default. Can be reversed with -u.
Print a summary of the options to GNU parallel and exit.
Use the replacement string replace-str instead of {}.
This option is a synonym for -Ireplace-str if replace-str is specified, and for -I{} otherwise. This option is deprecated; use -I instead.
Run up to N jobs in parallel. 0 means as many as possible. Default is 9.
Add N to the number of CPU cores. Run this many jobs in parallel. For compute intensive jobs -j +0 is useful as it will run number-of-cpu-cores jobs in parallel. See also --use-cpus-instead-of-cores.
Subtract N from the number of CPU cores. Run this many jobs in parallel. If the evaluated number is less than 1 then 1 will be used. See also --use-cpus-instead-of-cores.
Multiply N% with the number of CPU cores. Run this many jobs in parallel. If the evaluated number is less than 1 then 1 will be used. See also --use-cpus-instead-of-cores.
Keep sequence of output same as the order of input. If jobs 1 2 3 4 end in the sequence 3 1 4 2 the output will still be 1 2 3 4.
Use ssh's ControlMaster to make ssh connections faster. Useful if jobs run remote and are very fast to run.
Use at most max-args arguments per command line. Fewer than max-args arguments will be used if the size (see the -s option) is exceeded, unless the -x option is given, in which case GNU parallel will exit.
Only used with -m and -X.
Print the maximal number characters allowed on the command line and exit (used by GNU parallel itself to determine the line length on remote machines).
Print the number of physical CPUs and exit (used by GNU parallel itself to determine the number of physical CPUs on remote machines).
Print the number of cores and exit (used by GNU parallel itself to determine the number of cores on remote machines).
Prompt the user about whether to run each command line and read a line from the terminal. Only run the command line if the response starts with 'y' or 'Y'. Implies -t.
Quote command. This will quote the command line so special characters are not interpreted by the shell. See the section QUOTING. Most people will never need this. Quoting is disabled by default.
If the standard input only contains whitespace, do not run the command.
Transfer files from remote servers. --return is used with --sshlogin when the arguments are files on the remote servers. When processing is done the file filename will be transferred from the remote server using rsync and will be put relative to the default login dir. E.g.
echo foo/bar.txt | parallel \ --sshlogin server.example.com --return {.}.out touch {.}.out
This will transfer the file $HOME/foo/bar.out from the server server.example.com to the file foo/bar.out after running touch foo/bar.out on server.example.com.
echo /tmp/foo/bar.txt | parallel \ --sshlogin server.example.com --return {.}.out touch {.}.out
This will transfer the file /tmp/foo/bar.out from the server server.example.com to the file /tmp/foo/bar.out after running touch /tmp/foo/bar.out on server.example.com.
Multiple files can be transferred by repeating the options multiple times:
echo /tmp/foo/bar.txt | \ parallel --sshlogin server.example.com \ --return {.}.out --return {.}.out2 touch {.}.out {.}.out2
--return is often used with --transfer and --cleanup.
--return is ignored when used with --sshlogin : or when not used with --sshlogin.
Use at most max-chars characters per command line, including the command and initial-arguments and the terminating nulls at the ends of the argument strings. The largest allowed value is system-dependent, and is calculated as the argument length limit for exec, less the size of your environment. The default value is the maximum.
Display the limits on the command-line length which are imposed by the operating system and the -s option. Pipe the input from /dev/null (and perhaps specify --no-run-if-empty) if you don't want GNU parallel to do anything.
Distribute jobs to remote servers. The jobs will be run on a list of remote servers. GNU parallel will determine the number of CPU cores on the remote servers and run the number of jobs as specified by -j. If the number ncpu is given GNU parallel will use this number for number of CPUs on the host. Normally ncpu will not be needed.
An sshlogin is of the form:
[sshcommand [options]][username@]hostname
The sshlogin must not require a password.
The sshlogin ':' is special, it means 'no ssh' and will therefore run on the local machine.
To specify more sshlogins separate the sshlogins by comma or repeat the options multiple times.
For examples: see --sshloginfile.
The remote host must have GNU parallel installed.
--sshlogin is known to cause problems with -m and -X.
File with sshlogins. The file consists of sshlogins on separate lines. Empty lines and lines starting with '#' are ignored. Example:
server.example.com username@server2.example.com 8/my-8-core-server.example.com 2/myusername@my-dualcore.example.net # This server has SSH running on port 2222 ssh -p 2222 server.example.net 4/ssh -p 2222 quadserver.example.net # Use a different ssh program myssh -p 2222 -l compute hexacpu.example.net # Use a different ssh program with default number of cores //usr/local/bin/myssh -p 2222 -l compute hexacpu.example.net # Use a different ssh program with 6 cores 6//usr/local/bin/myssh -p 2222 -l compute hexacpu.example.net # Assume 16 cores on the local machine 16/:
Silent. The job to be run will not be printed. This is the default. Can be reversed with -v.
Print the command line on the standard error output before executing it.
See also -v.
Transfer files to remote servers. --transfer is used with --sshlogin when the arguments are files and should be transferred to the remote servers. The files will be transferred using rsync and will be put relative to the default login dir. E.g.
echo foo/bar.txt | parallel \ --sshlogin server.example.com --transfer wc
This will transfer the file foo/bar.txt to the server server.example.com to the file $HOME/foo/bar.txt before running wc foo/bar.txt on server.example.com.
echo /tmp/foo/bar.txt | parallel \ --sshlogin server.example.com --transfer wc
This will transfer the file foo/bar.txt to the server server.example.com to the file /tmp/foo/bar.txt before running wc /tmp/foo/bar.txt on server.example.com.
--transfer is often used with --return and --cleanup.
--transfer is ignored when used with --sshlogin : or when not used with --sshlogin.
Transfer, Return, Cleanup. Short hand for:
--transfer --return filename --cleanup
Ungroup output. Output is printed as soon as possible. This may cause output from different commands to be mixed. GNU parallel runs faster with -u. Can be reversed with -g.
Use the replacement string replace-str instead of {.} for input line without extension.
Count the number of physical CPUs instead of cores. When computing how many jobs to run in parallel relative to the number of cores you can ask GNU parallel to instead look at the number of physical CPUs. This will make sense for computers that have hyperthreading as two jobs running on one CPU with hyperthreading will run slower than two jobs running on two physical CPUs. Some multi-core CPUs can run faster if only one thread is running per physical CPU. Most users will not need this option.
Verbose. Print the job to be run on STDOUT. Can be reversed with --silent. See also -t.
Print the version GNU parallel and exit.
Multiple. Insert as many arguments as the command line length permits. If {} is not used the arguments will be appended to the line. If {} is used multiple times each {} will be replaced with all the arguments.
Support for -m with --sshlogin is limited and may fail.
xargs with context replace. This works like -m except if {} is part of a word (like pic{}.jpg) then the whole word will be repeated. Normally -X will do the right thing, whereas -m can give surprising results if {} is used as part of a word.
Support for -X with --sshlogin is limited and may fail.
GNU parallel can work similar to xargs -n1.
To compress all html files using gzip run:
find . -name '*.html' | parallel gzip
When moving a lot of files like this: mv * destdir you will sometimes get the error:
bash: /bin/mv: Argument list too long
because there are too many files. You can instead do:
ls | parallel mv {} destdir
This will run mv for each file. It can be done faster if mv gets as many arguments that will fit on the line:
ls | parallel -m mv {} destdir
To remove the files pict0000.jpg .. pict9999.jpg you could do:
seq -f %04g 0 9999 | parallel rm pict{}.jpg
You could also do:
seq -f %04g 0 9999 | perl -pe 's/(.*)/pict$1.jpg/' | parallel -m rm
The first will run rm 10000 times, while the last will only run rm as many times needed to keep the command line length short enough to avoid Argument list too long (it typically runs 1-2 times).
You could also run:
seq -f %04g 0 9999 | parallel -X rm pict{}.jpg
This will also only run rm as many times needed to keep the command line length short enough.
If ImageMagick is installed this will generate a thumbnail of a jpg file:
convert -geometry 120 foo.jpg thumb_foo.jpg
If the system has more than 1 CPU core it can be run with number-of-cpu-cores jobs in parallel (-j +0). This will do that for all jpg files in a directory:
ls *.jpg | parallel -j +0 convert -geometry 120 {} thumb_{}
To do it recursively use find:
find . -name '*.jpg' | parallel -j +0 convert -geometry 120 {} {}_thumb.jpg
Notice how the argument has to start with {} as {} will include path (e.g. running convert -geometry 120 ./foo/bar.jpg thumb_./foo/bar.jpg would clearly be wrong). The command will generate files like ./foo/bar.jpg_thumb.jpg.
Use {.} to avoid the extra .jpg in the file name. This command will make files like ./foo/bar_thumb.jpg:
find . -name '*.jpg' | parallel -j +0 convert -geometry 120 {} {.}_thumb.jpg
This will generate an uncompressed version of .gz-files next to the .gz-file:
ls *.gz | parallel zcat {} ">"{.}
Quoting of > is necessary to postpone the redirection. Another solution is to quote the whole command:
ls *.gz | parallel "zcat {} >{.}"
Other special shell charaters (such as * ; $ > < | >> <<) also needs to be put in quotes, as they may otherwise be interpreted by the shell and not given to GNU parallel.
A job can consist of several commands. This will print the number of files in each directory:
ls | parallel 'echo -n {}" "; ls {}|wc -l'
To put the output in a file called <name>.dir:
ls | parallel '(echo -n {}" "; ls {}|wc -l) > {}.dir'
When processing files removing the file extension using {.} is often useful.
Create a directory for each zip-file and unzip it in that dir:
ls *zip | parallel 'mkdir {.}; cd {.}; unzip ../{}'
Recompress all .gz files in current directory using bzip2 running 1 job per CPU core in parallel:
ls *.gz | parallel -j+0 "zcat {} | bzip2 >{.}.bz2 && rm {}"
for-loops like this:
(for x in `cat list` ; do do_something $x done) | process_output
and while-loops like this:
cat list | (while read x ; do do_something $x done) | process_output
can be written like this:
cat list | parallel do_something | process_output
If the processing requires more steps the for-loop like this:
(for x in `cat list` ; do no_extension=${x%.png}; do_something $x scale $no_extension.jpg do_step2 <$x $no_extension done) | process_output
and while-loops like this:
cat list | (while read x ; do no_extension=${x%.png}; do_something $x scale $no_extension.jpg do_step2 <$x $no_extension done) | process_output
can be written like this:
cat list | parallel "do_something {} scale {.}.jpg ; do_step2 <{} {.}" | process_output
When runnning jobs that output data, you often do not want the output of multiple jobs to run together. GNU parallel defaults to grouping the output of each job, so the output is printed when the job finishes. If you want the output to be printed while the job is running you can use -u.
Compare the output of:
(echo foss.org.my; echo debian.org; echo freenetproject.org) | parallel traceroute
to the output of:
(echo foss.org.my; echo debian.org; echo freenetproject.org) | parallel -u traceroute
Normally the output of a job will be printed as soon as it completes. Sometimes you want the order of the output to remain the same as the order of the input. This is often important, if the output is used as input for another system. -k will make sure the order of output will be in the same order as input even if later jobs end before earlier jobs.
Append a string to every line in a text file:
cat textfile | parallel -k echo {} append_string
If you remove -k some of the lines may come out in the wrong order.
Another example is traceroute:
(echo foss.org.my; echo debian.org; echo freenetproject.org) | parallel traceroute
will give traceroute of foss.org.my, debian.org and freenetproject.org, but it will be sorted according to which job completed first.
To keep the order the same as input run:
(echo foss.org.my; echo debian.org; echo freenetproject.org) | parallel -k traceroute
This will make sure the traceroute to foss.org.my will be printed first.
To run commands on a remote computer SSH needs to be set up and you must be able to login without entering a password (ssh-agent may be handy).
To run echo on server.example.com:
seq 1 10 | parallel --sshlogin server.example.com echo
To run commands on more than one remote computer run:
seq 1 10 | parallel --sshlogin server.example.com,server2.example.net echo
Or:
seq 1 10 | parallel --sshlogin server.example.com \ --sshlogin server2.example.net echo
If the login username is foo on server2.example.net use:
seq 1 10 | parallel --sshlogin server.example.com \ --sshlogin foo@server2.example.net echo
To distribute the commands to a list of machines, make a file mymachines with all the machines:
server.example.com foo@server2.example.com server3.example.com
Then run:
seq 1 10 | parallel --sshloginfile mymachines echo
To include the local machine add the special sshlogin ':' to the list:
server.example.com foo@server2.example.com server3.example.com :
If the number of CPU cores on the remote servers is not identified correctly the number of CPU cores can be added in front. Here the server has 8 CPU cores.
seq 1 10 | parallel --sshlogin 8/server.example.com echo
To recompress gzipped files with bzip2 using a remote server run:
find logs/ -name '*.gz' | \ parallel --sshlogin server.example.com \ --transfer "zcat {} | bzip2 -9 >{.}.bz2"
This will list the .gz-files in the logs directory and all directories below. Then it will transfer the files to server.example.com to the corresponding directory in $HOME/logs. On server.example.com the file will be recompressed using zcat and bzip2 resulting in the corresponding file with .gz replaced with .bz2.
If you want the file to be transferred back to the local machine add --return {.}.bz2:
find logs/ -name '*.gz' | \ parallel --sshlogin server.example.com \ --transfer --return {.}.bz2 "zcat {} | bzip2 -9 >{.}.bz2"
After the recompressing is done the .bz2-file is transferred back to the local machine and put next to the original .gz-file.
If you want to delete the transferred files on the remote machine add --cleanup. This will remove both the file transferred to the remote machine and the files transferred from the remote machine:
find logs/ -name '*.gz' | \ parallel --sshlogin server.example.com \ --transfer --return {.}.bz2 --cleanup "zcat {} | bzip2 -9 >{.}.bz2"
If you want run on several servers add the servers to --sshlogin either using ',' or multiple --sshlogin:
find logs/ -name '*.gz' | \ parallel --sshlogin server.example.com,server2.example.com \ --sshlogin server3.example.com \ --transfer --return {.}.bz2 --cleanup "zcat {} | bzip2 -9 >{.}.bz2"
You can add the local machine using --sshlogin :. This will disable the removing and transferring for the local machine only:
find logs/ -name '*.gz' | \ parallel --sshlogin server.example.com,server2.example.com \ --sshlogin server3.example.com \ --sshlogin : \ --transfer --return {.}.bz2 --cleanup "zcat {} | bzip2 -9 >{.}.bz2"
Often --transfer, --return and --cleanup are used together. They can be shortened to --trc:
find logs/ -name '*.gz' | \ parallel --sshlogin server.example.com,server2.example.com \ --sshlogin server3.example.com \ --sshlogin : \ --trc {.}.bz2 "zcat {} | bzip2 -9 >{.}.bz2"
With the file mymachines containing the compute machines it becomes:
find logs/ -name '*.gz' | parallel --sshloginfile mymachines \ --trc {.}.bz2 "zcat {} | bzip2 -9 >{.}.bz2"
GNU parallel can work similar to cat | sh.
A ressource inexpensive job is a job that takes very little CPU, disk I/O and network I/O. Ping is an example of a ressource inexpensive job. wget is too - if the webpages are small.
The content of the file jobs_to_run:
ping -c 1 10.0.0.1 wget http://status-server/status.cgi?ip=10.0.0.1 ping -c 1 10.0.0.2 wget http://status-server/status.cgi?ip=10.0.0.2 ... ping -c 1 10.0.0.255 wget http://status-server/status.cgi?ip=10.0.0.255
To run 100 processes simultaneously do:
parallel -j 100 < jobs_to_run
As there is not a command the option -c is default because the jobs needs to be evaluated by the shell.
For more advanced use quoting may be an issue. The following will print the filename for each line that has exactly 2 columns:
perl -ne '/^\S+\s+\S+$/ and print $ARGV,"\n"' file
This can be done by GNU parallel using:
ls | parallel "perl -ne '/^\\S+\\s+\\S+$/ and print \$ARGV,\"\\n\"'"
Notice how \'s, "'s, and $'s needs to be quoted. GNU parallel can do the quoting by using option -q:
ls | parallel -q perl -ne '/^\S+\s+\S+$/ and print $ARGV,"\n"'
However, this means you cannot make the shell interpret special characters. For example this will not work:
ls *.gz | parallel -q "zcat {} >{.}"
ls *.gz | parallel -q "zcat {} | bzip2 >{.}.bz2"
because > and | need to be interpreted by the shell.
If you get errors like:
sh: -c: line 0: syntax error near unexpected token
then you might try using -q.
If you are using bash process substitution like <(cat foo) then you may try -q and prepending command with bash -c:
ls | parallel -q bash -c 'wc -c <(echo {})'
Or for substituting output:
ls | parallel -q bash -c 'tar c {} | tee >(gzip >{}.tar.gz) | bzip2 >{}.tar.bz2'
Conclusion: To avoid dealing with the quoting problems it may be easier just to write a small script and have GNU parallel call that script.
If you want a list of the jobs currently running you can run:
killall -USR1 parallel
GNU parallel will then print the currently running jobs on STDERR.
If you regret starting a lot of jobs you can simply break GNU parallel, but if you want to make sure you do not have halfcompleted jobs you should send the signal SIGTERM to GNU parallel:
killall -TERM parallel
This will tell GNU parallel to not start any new jobs, but wait until the currently running jobs are finished before exiting.
find -exec offer some of the same possibilites as GNU parallel.
find -exec only works on files. So processing other input (such as hosts or URLs) will require creating these inputs as files. find -exec has no support for running commands in parallel.
xargs offer some of the same possibilites as GNU parallel.
xargs deals badly with special characters (such as space, ' and "). To see the problem try this:
touch important_file touch 'not important_file' ls not* | xargs rm mkdir -p '12" records' ls | xargs rmdir
You can specify -0 or -d "\n", but many input generators are not optimized for using NUL as separator but are optimized for newline as separator. E.g head, tail, awk, ls, echo, sed, tar -v, perl (-0 and \0 instead of \n), locate (requires using -0), find (requires using -print0), grep (requires user to use -z or -Z).
So GNU parallel's newline separation can be emulated with:
cat | xargs -d "\n" -n1 command
xargs can run a given number of jobs in parallel, but has no support for running number-of-cpu-cores jobs in parallel.
xargs has no support for grouping the output, therefore output may run together, e.g. the first half of a line is from one process and the last half of the line is from another process.
xargs has no support for keeping the order of the output, therefore if running jobs in parallel using xargs the output of the second job cannot be postponed till the first job is done.
xargs has no support for running jobs on remote machines.
xargs has no support for context replace, so you will have to create the arguments.
If you use a replace string in xargs (-I) you can not force xargs to use more than one argument.
Quoting in xargs works like -q in GNU parallel. This means composed commands and redirection requires using bash -c.
ls | parallel "wc {} > {}.wc"
becomes
ls | xargs -d "\n" -P9 -I {} bash -c "wc {} > {}.wc"
and
ls | parallel "echo {}; ls {}|wc"
becomes
ls | xargs -d "\n" -P9 -I {} bash -c "echo {}; ls {}|wc"
ppss is also a tool for running jobs in parallel.
The output of ppss is status information and thus not useful for using as input for another command. The output from the jobs are put into files.
The argument replace string ($ITEM) cannot be changed and must be quoted - thus arguments containing special characters (space '"&!*) may cause problems. More than one argument is not supported. File names containing newlines are not processed correctly. When reading input from a file null cannot be used terminator. ppss needs to read the whole input file before starting any jobs.
Output and status information is stored in ppss_dir and thus requires cleanup when completed. If the dir is not removed before running ppss again it may cause nothing to happen as ppss thinks the task is already done. GNU parallel will normally not need cleaning up if running locally and will only need cleaning up if stopped abnormally and running remote (--cleanup may not complete if stopped abnormally).
Here are the examples from ppss's manual page with the equivalent using parallel:
./ppss.sh standalone -d /path/to/files -c 'gzip '
find /path/to/files -type f | parallel -j+0 gzip
./ppss.sh standalone -d /path/to/files -c 'cp "$ITEM" /destination/dir '
find /path/to/files -type f | parallel -j+0 cp {} /destination/dir
./ppss.sh standalone -f list-of-urls.txt -c 'wget -q '
parallel -a list-of-urls.txt wget -q
./ppss.sh standalone -f list-of-urls.txt -c 'wget -q "$ITEM"'
parallel -a list-of-urls.txt wget -q {}
./ppss config -C config.cfg -c 'encode.sh ' -d /source/dir -m 192.168.1.100 -u ppss -k ppss-key.key -S ./encode.sh -n nodes.txt -o /some/output/dir --upload --download
./ppss deploy -C config.cfg
./ppss start -C config
# parallel does not use configs. If you want a different username put it in nodes.txt: user@hostname
find source/dir -type f | parallel --sshloginfile nodes.txt --trc {.}.mp3 lame -a {} -o {.}.mp3 --preset standard --quiet
./ppss stop -C config.cfg
killall -TERM parallel
./ppss pause -C config.cfg
Press: CTRL-Z or killall -SIGTSTP parallel
./ppss continue -C config.cfg
Enter: fg or killall -SIGCONT parallel
./ppss.sh status -C config.cfg
killall -SIGUSR1 parallel # Not quite equivalent: Only shows the currently running jobs
pexec is also a tool for running jobs in parallel.
Here are the examples from pexec's info page with the equivalent using parallel:
pexec -o sqrt-%s.dat -p "$(seq 10)" -e NUM -n 4 -c -- \ 'echo "scale=10000;sqrt($NUM)" | bc'
seq 10 | parallel -j4 'echo "scale=10000;sqrt({})" | bc > sqrt-{}.dat'
pexec -p "$(ls myfiles*.ext)" -i %s -o %s.sort -- sort
ls myfiles*.ext | parallel sort {} ">{}.sort"
pexec -f image.list -n auto -e B -u star.log -c -- \ 'fistar $B.fits -f 100 -F id,x,y,flux -o $B.star'
parallel -a image.list -j+0 \ 'fistar {}.fits -f 100 -F id,x,y,flux -o {}.star' 2>star.log
pexec -r *.png -e IMG -c -o - -- \ 'convert $IMG ${IMG%.png}.jpeg ; "echo $IMG: done"'
ls *.png | parallel 'convert {} {.}.jpeg; echo {}: done'
pexec -r *.png -i %s -o %s.jpg -c 'pngtopnm | pnmtojpeg'
ls *.png | parallel 'pngtopnm < {} | pnmtojpeg > {}.jpg'
for p in *.png ; do echo ${p%.png} ; done | \ pexec -f - -i %s.png -o %s.jpg -c 'pngtopnm | pnmtojpeg'
ls *.png | parallel 'pngtopnm < {} | pnmtojpeg > {.}.jpg'
LIST=$(for p in *.png ; do echo ${p%.png} ; done) pexec -r $LIST -i %s.png -o %s.jpg -c 'pngtopnm | pnmtojpeg'
ls *.png | parallel 'pngtopnm < {} | pnmtojpeg > {.}.jpg'
pexec -n 8 -r *.jpg -y unix -e IMG -c \ 'pexec -j -m blockread -d $IMG | \ jpegtopnm | pnmscale 0.5 | pnmtojpeg | \ pexec -j -m blockwrite -s th_$IMG'
GNU parallel does not support mutexes directly but uses mutex to do that.
ls *jpg | parallel -j8 'mutex -m blockread cat {} | jpegtopnm |' \ 'pnmscale 0.5 | pnmtojpeg | mutex -m blockwrite cat > th_{}'
dxargs does not deal well with more simultaneous jobs than SSHD's MaxStartup. dxargs is only built for remote run jobs, but does not support transferring of files.
middleman(mdm) is also a tool for running jobs in parallel.
Here are the shellscripts of http://mdm.berlios.de/usage.html ported to parallel use:
seq 1 19 | parallel -j+0 buffon -o - | sort -n > result
cat files | parallel -j+0 cmd
The environment variable $PARALLEL will be used as default options for GNU parallel. However, because some options take arguments the options need to be split into groups in which only the last option takes an argument. Each group of options should be put on a line of its own.
The file ~/.parallelrc will be read if it exists. It should be formatted like the environment variable $PARALLEL. Lines starting with '#' will be ignored.
cat list | parallel -j1 -k -v ls
can be written as:
cat list | PARALLEL="-kvj1" parallel ls
cat list | parallel -j1 -k -v -S"myssh user@server" ls
can be written as:
cat list | PARALLEL="-kvj1 -Smyssh user@server" parallel echo
Notice the newline in the middel is needed because both -S and -j take an argument and thus both need to be at the end of a group.
Filenames beginning with '-' can cause some commands to give unexpected results, as it will often be interpreted as an option.
Report bugs to <bug-parallel@gnu.org>.
Copyright (C) 2007-10-18 Ole Tange, http://ole.tange.dk
Copyright (C) 2008,2009,2010 Ole Tange, http://ole.tange.dk
Copyright (C) 2010 Ole Tange, http://ole.tange.dk and Free Software Foundation, Inc.
Parts of the manual concerning xargs compatibility is inspired by the manual of xargs from GNU findutils 4.4.2.
Copyright (C) 2007,2008,2009,2010 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or at your option any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
Permission is granted to copy, distribute and/or modify this documentation under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the file fdl.txt.
You are free:
to copy, distribute and transmit the work
to adapt the work
Under the following conditions:
You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work).
If you alter, transform, or build upon this work, you may distribute the resulting work only under the same, similar or a compatible license.
With the understanding that:
Any of the above conditions can be waived if you get permission from the copyright holder.
Where the work or any of its elements is in the public domain under applicable law, that status is in no way affected by the license.
In no way are any of the following rights affected by the license:
Your fair dealing or fair use rights, or other applicable copyright exceptions and limitations;
The author's moral rights;
Rights other persons may have either in the work itself or in how the work is used, such as publicity or privacy rights.
For any reuse or distribution, you must make clear to others the license terms of this work.
A copy of the full license is included in the file as cc-by-sa.txt.
GNU parallel uses Perl, and the Perl modules Getopt::Long, IPC::Open3, Symbol, IO::File, POSIX, and File::Temp.
find(1), xargs(1), pexec(1), ppss(1)