mirror of
https://git.savannah.gnu.org/git/parallel.git
synced 2024-11-22 05:57:54 +00:00
432 lines
16 KiB
Groff
432 lines
16 KiB
Groff
.\" Automatically generated by Pod::Man 2.1801 (Pod::Simple 3.05)
|
|
.\"
|
|
.\" Standard preamble:
|
|
.\" ========================================================================
|
|
.de Sp \" Vertical space (when we can't use .PP)
|
|
.if t .sp .5v
|
|
.if n .sp
|
|
..
|
|
.de Vb \" Begin verbatim text
|
|
.ft CW
|
|
.nf
|
|
.ne \\$1
|
|
..
|
|
.de Ve \" End verbatim text
|
|
.ft R
|
|
.fi
|
|
..
|
|
.\" Set up some character translations and predefined strings. \*(-- will
|
|
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
|
|
.\" double quote, and \*(R" will give a right double quote. \*(C+ will
|
|
.\" give a nicer C++. Capital omega is used to do unbreakable dashes and
|
|
.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
|
|
.\" nothing in troff, for use with C<>.
|
|
.tr \(*W-
|
|
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
|
|
.ie n \{\
|
|
. ds -- \(*W-
|
|
. ds PI pi
|
|
. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
|
|
. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
|
|
. ds L" ""
|
|
. ds R" ""
|
|
. ds C` ""
|
|
. ds C' ""
|
|
'br\}
|
|
.el\{\
|
|
. ds -- \|\(em\|
|
|
. ds PI \(*p
|
|
. ds L" ``
|
|
. ds R" ''
|
|
'br\}
|
|
.\"
|
|
.\" Escape single quotes in literal strings from groff's Unicode transform.
|
|
.ie \n(.g .ds Aq \(aq
|
|
.el .ds Aq '
|
|
.\"
|
|
.\" If the F register is turned on, we'll generate index entries on stderr for
|
|
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
|
|
.\" entries marked with X<> in POD. Of course, you'll have to process the
|
|
.\" output yourself in some meaningful fashion.
|
|
.ie \nF \{\
|
|
. de IX
|
|
. tm Index:\\$1\t\\n%\t"\\$2"
|
|
..
|
|
. nr % 0
|
|
. rr F
|
|
.\}
|
|
.el \{\
|
|
. de IX
|
|
..
|
|
.\}
|
|
.\"
|
|
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
|
|
.\" Fear. Run. Save yourself. No user-serviceable parts.
|
|
. \" fudge factors for nroff and troff
|
|
.if n \{\
|
|
. ds #H 0
|
|
. ds #V .8m
|
|
. ds #F .3m
|
|
. ds #[ \f1
|
|
. ds #] \fP
|
|
.\}
|
|
.if t \{\
|
|
. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
|
|
. ds #V .6m
|
|
. ds #F 0
|
|
. ds #[ \&
|
|
. ds #] \&
|
|
.\}
|
|
. \" simple accents for nroff and troff
|
|
.if n \{\
|
|
. ds ' \&
|
|
. ds ` \&
|
|
. ds ^ \&
|
|
. ds , \&
|
|
. ds ~ ~
|
|
. ds /
|
|
.\}
|
|
.if t \{\
|
|
. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
|
|
. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
|
|
. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
|
|
. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
|
|
. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
|
|
. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
|
|
.\}
|
|
. \" troff and (daisy-wheel) nroff accents
|
|
.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
|
|
.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
|
|
.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
|
|
.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
|
|
.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
|
|
.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
|
|
.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
|
|
.ds ae a\h'-(\w'a'u*4/10)'e
|
|
.ds Ae A\h'-(\w'A'u*4/10)'E
|
|
. \" corrections for vroff
|
|
.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
|
|
.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
|
|
. \" for low resolution devices (crt and lpr)
|
|
.if \n(.H>23 .if \n(.V>19 \
|
|
\{\
|
|
. ds : e
|
|
. ds 8 ss
|
|
. ds o a
|
|
. ds d- d\h'-1'\(ga
|
|
. ds D- D\h'-1'\(hy
|
|
. ds th \o'bp'
|
|
. ds Th \o'LP'
|
|
. ds ae ae
|
|
. ds Ae AE
|
|
.\}
|
|
.rm #[ #] #H #V #F C
|
|
.\" ========================================================================
|
|
.\"
|
|
.IX Title "PARALLEL 1"
|
|
.TH PARALLEL 1 "2009-04-27" "perl v5.10.0" "User Contributed Perl Documentation"
|
|
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
|
|
.\" way too many mistakes in technical documents.
|
|
.if n .ad l
|
|
.nh
|
|
.SH "NAME"
|
|
parallel \- build and execute command lines from standard input in parallel
|
|
.SH "SYNOPSIS"
|
|
.IX Header "SYNOPSIS"
|
|
\&\fBparallel\fR [\-0cfgqsuvxX] [\-j num] [command [arguments]] < list_of_arguments
|
|
.SH "DESCRIPTION"
|
|
.IX Header "DESCRIPTION"
|
|
For each line of input \fBparallel\fR will execute \fBcommand\fR with the
|
|
line as arguments. If no \fBcommand\fR is given the line of input is
|
|
executed. \fBparallel\fR can often be used as a substitute for \fBxargs\fR
|
|
or \fBcat | sh\fR.
|
|
.PP
|
|
Several lines will be run in parallel.
|
|
.IP "\fIcommand\fR" 9
|
|
.IX Item "command"
|
|
Command to execute. If \fBcommand\fR or the following arguments contain {}
|
|
every instance will be substituted with the input line. Setting a
|
|
command also invokes \fB\-f\fR.
|
|
.Sp
|
|
If \fBcommand\fR is given, \fBparallel\fR will behave similar to \fBxargs\fR. If
|
|
\&\fBcommand\fR is not given \fBparallel\fR will behave similar to \fBcat | sh\fR.
|
|
.IP "\fB\-0\fR" 9
|
|
.IX Item "-0"
|
|
Use \s-1NUL\s0 as delimiter. Normally input lines will end in \en
|
|
(newline). If they end in \e0 (\s-1NUL\s0), then use this option. It is useful
|
|
for processing filenames that may contain \en (newline).
|
|
.IP "\fB\-c\fR" 9
|
|
.IX Item "-c"
|
|
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 \fBcommand\fR is not set. Can be reversed with \fB\-f\fR.
|
|
.IP "\fB\-f\fR" 9
|
|
.IX Item "-f"
|
|
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
|
|
\&\fBcommand\fR is set. Can be reversed with \fB\-c\fR.
|
|
.IP "\fB\-g\fR" 9
|
|
.IX Item "-g"
|
|
Group output. Output from each jobs is grouped together and is only
|
|
printed when the command is finished. \s-1STDERR\s0 first followed by \s-1STDOUT\s0.
|
|
\&\fB\-g\fR is the default. Can be reversed with \fB\-u\fR.
|
|
.IP "\fB\-j\fR \fIN\fR" 9
|
|
.IX Item "-j N"
|
|
Run N jobs in parallel. 0 means as many as possible. Default is 10.
|
|
.IP "\fB\-j\fR \fI+N\fR" 9
|
|
.IX Item "-j +N"
|
|
Add N to the number of CPUs. Run this many jobs in parallel. For
|
|
compute intensive jobs \fI\-j +0\fR is useful as it will run
|
|
number-of-cpus jobs in parallel.
|
|
.IP "\fB\-j\fR \fI\-N\fR" 9
|
|
.IX Item "-j -N"
|
|
Subtract N from the number of CPUs. Run this many jobs in parallel.
|
|
If the evaluated number is less than 1 then 1 will be used.
|
|
.IP "\fB\-j\fR \fIN\fR%" 9
|
|
.IX Item "-j N%"
|
|
Multiply N% with the number of CPUs. Run this many jobs in parallel.
|
|
If the evaluated number is less than 1 then 1 will be used.
|
|
.IP "\fB\-q\fR" 9
|
|
.IX Item "-q"
|
|
Quote \fBcommand\fR. This will quote the command line so special
|
|
characters are not interpreted by the shell. See the section
|
|
\&\s-1QUOTING\s0. Most people will never need this. Quoting is disabled by
|
|
default.
|
|
.IP "\fB\-s\fR" 9
|
|
.IX Item "-s"
|
|
Silent. The job to be run will not be printed. This is the default.
|
|
Can be reversed with \fB\-v\fR.
|
|
.IP "\fB\-u\fR" 9
|
|
.IX Item "-u"
|
|
Ungroup output. Output is printed as soon as possible. This may cause
|
|
output from different commands to be mixed. Can be reversed with \fB\-g\fR.
|
|
.IP "\fB\-v\fR" 9
|
|
.IX Item "-v"
|
|
Verbose. Print the job to be run. Can be reversed with \fB\-s\fR.
|
|
.IP "\fB\-x\fR" 9
|
|
.IX Item "-x"
|
|
xargs. 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.
|
|
.IP "\fB\-X\fR" 9
|
|
.IX Item "-X"
|
|
xargs with context replace. This works like \fB\-x\fR except if {} is part
|
|
of a word (like \fIpic{}.jpg\fR) then the whole word will be repeated.
|
|
.SH "EXAMPLE 1: Working as cat | sh. Ressource inexpensive jobs and evaluation"
|
|
.IX Header "EXAMPLE 1: Working as cat | sh. Ressource inexpensive jobs and evaluation"
|
|
\&\fBparallel\fR can work similar to \fBcat | sh\fR.
|
|
.PP
|
|
A ressource inexpensive job is a job that takes very little \s-1CPU\s0, disk
|
|
I/O and network I/O. Ping is an example of a ressource inexpensive
|
|
job. wget is too \- if the webpages are small.
|
|
.PP
|
|
The content of the file jobs_to_run:
|
|
.PP
|
|
.Vb 7
|
|
\& 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
|
|
.Ve
|
|
.PP
|
|
To run 100 processes simultaneously do:
|
|
.PP
|
|
\&\fBparallel \-j 100 < jobs_to_run\fR
|
|
.PP
|
|
As there is not a \fBcommand\fR the option \fB\-c\fR is default because the
|
|
jobs needs to be evaluated by the shell.
|
|
.SH "EXAMPLE 2: Working as xargs \-n1. Argument appending"
|
|
.IX Header "EXAMPLE 2: Working as xargs -n1. Argument appending"
|
|
\&\fBparallel\fR can work similar to \fBxargs \-n1\fR.
|
|
.PP
|
|
To output all html files run:
|
|
.PP
|
|
\&\fBfind . \-name '*.html' | parallel cat\fR
|
|
.PP
|
|
As there is a \fBcommand\fR the option \fB\-f\fR is default because the
|
|
filenames needs to be protected from the shell in case a filename
|
|
contains special characters.
|
|
.SH "EXAMPLE 3: Compute intensive jobs and substitution"
|
|
.IX Header "EXAMPLE 3: Compute intensive jobs and substitution"
|
|
If ImageMagick is installed this will generate a thumbnail of a jpg
|
|
file:
|
|
.PP
|
|
\&\fBconvert \-geometry 120 foo.jpg thumb_foo.jpg\fR
|
|
.PP
|
|
If the system has more than 1 \s-1CPU\s0 it can be run with number-of-cpus
|
|
jobs in parallel (\-j +0). This will do that for all jpg files in a
|
|
directory:
|
|
.PP
|
|
\&\fBls *.jpg | parallel \-j +0 convert \-geometry 120 {} thumb_{}\fR
|
|
.PP
|
|
To do it recursively use \fBfind\fR:
|
|
.PP
|
|
\&\fBfind . \-name '*.jpg' | parallel \-j +0 convert \-geometry 120 {} {}_thumb.jpg\fR
|
|
.PP
|
|
Notice how the argument has to start with {} as {} will include path
|
|
(e.g. running \fBconvert \-geometry 120 ./foo/bar.jpg
|
|
thumb_./foo/bar.jpg\fR would clearly be wrong). It will result in files
|
|
like ./foo/bar.jpg_thumb.jpg. If that is not wanted this can fix it:
|
|
.PP
|
|
.Vb 3
|
|
\& find . \-name \*(Aq*.jpg\*(Aq | \e
|
|
\& perl \-pe \*(Aqchomp; $a=$_; s:/([^/]+)$:/thumb_$1:; $_="convert \-geometry 120 $a $_\en"\*(Aq | \e
|
|
\& parallel \-c \-j +0
|
|
.Ve
|
|
.PP
|
|
Unfortunately this will not work if the filenames contain special
|
|
characters (such as space or quotes). If you have \fBren\fR installed this
|
|
is a better solution:
|
|
.PP
|
|
.Vb 2
|
|
\& find . \-name \*(Aq*.jpg\*(Aq | parallel \-j +0 convert \-geometry 120 {} {}_thumb.jpg
|
|
\& find . \-name \*(Aq*_thumb.jpg\*(Aq | ren \*(Aqs:/([^/]+)_thumb.jpg$:/thumb_$1:\*(Aq
|
|
.Ve
|
|
.SH "EXAMPLE 4: Substitution and redirection"
|
|
.IX Header "EXAMPLE 4: Substitution and redirection"
|
|
This will compare all files in the dir to the file foo and save the
|
|
diffs in corresponding .diff files:
|
|
.PP
|
|
\&\fBls | parallel diff {} foo "\fR>\fB"{}.diff\fR
|
|
.PP
|
|
Quoting of > is necessary to postpone the redirection. Another
|
|
solution is to quote the whole command:
|
|
.PP
|
|
\&\fBls | parallel "diff {} foo \fR>\fB{}.diff"\fR
|
|
.SH "EXAMPLE 5: Composed commands"
|
|
.IX Header "EXAMPLE 5: Composed commands"
|
|
A job can consist of several commands. This will print the number of
|
|
files in each directory:
|
|
.PP
|
|
\&\fBls | parallel 'echo \-n {}\*(L" \*(R"; ls {}|wc \-l'\fR
|
|
.PP
|
|
To put the output in a file called <name>.dir:
|
|
.PP
|
|
\&\fBls | parallel '(echo \-n {}\*(L" \*(R"; ls {}|wc \-l) \fR>\fB {}.dir'\fR
|
|
.SH "EXAMPLE 6: Context replace"
|
|
.IX Header "EXAMPLE 6: Context replace"
|
|
To remove the files \fIpict1000.jpg\fR .. \fIpict9999.jpg\fR you could do:
|
|
.PP
|
|
\&\fBseq 1000 9999 | parallel rm pict{}.jpg\fR
|
|
.PP
|
|
You could also do:
|
|
.PP
|
|
\&\fBseq 1000 9999 | perl \-pe 's/(.*)/pict$1.jpg/' | parallel \-x rm\fR
|
|
.PP
|
|
The first will run \fBrm\fR 8999 times, while the last will only run
|
|
\&\fBrm\fR as many times needed to keep the command line length short
|
|
enough.
|
|
.PP
|
|
You could also run:
|
|
.PP
|
|
\&\fBseq 1000 9999 | parallel \-X rm pict{}.jpg\fR
|
|
.PP
|
|
This will also only run \fBrm\fR as many times needed to keep the command
|
|
line length short enough.
|
|
.SH "QUOTING"
|
|
.IX Header "QUOTING"
|
|
For more advanced use quoting may be an issue. The following will
|
|
print the filename for each line that has exactly 2 columns:
|
|
.PP
|
|
\&\fBperl \-ne '/^\eS+\es+\eS+$/ and print \f(CB$ARGV\fB,\*(L"\en\*(R"' file\fR
|
|
.PP
|
|
This can be done by \fBparallel\fR using:
|
|
.PP
|
|
\&\fBls | parallel \*(L"perl \-ne '/^\e\eS+\e\es+\e\eS+$/ and print \e$ARGV,\e\*(R"\e\en\e\*(L"'\*(R"\fR
|
|
.PP
|
|
Notice how \e's, "'s, and $'s needs to be quoted. \fBparallel\fR can do
|
|
the quoting by using option \fB\-q\fR:
|
|
.PP
|
|
\&\fBls | parallel \-q perl \-ne '/^\eS+\es+\eS+$/ and print \f(CB$ARGV\fB,\*(L"\en\*(R"'\fR
|
|
.PP
|
|
However, this means you cannot make the shell interpret special
|
|
characters. For example this \fBwill not work\fR:
|
|
.PP
|
|
\&\fBls | parallel \-q "diff {} foo \fR>\fB{}.diff"\fR
|
|
.PP
|
|
because > needs to be interpreted by the shell.
|
|
.PP
|
|
If you get errors like:
|
|
.PP
|
|
\&\fBsh: \-c: line 0: syntax error near unexpected token\fR
|
|
.PP
|
|
then you might try using \fB\-q\fR.
|
|
.PP
|
|
\&\fBConclusion\fR: To avoid dealing with the quoting problems it may be
|
|
easier just to write a small script and have \fBparallel\fR call that
|
|
script.
|
|
.SH "DIFFERENCES BETWEEN xargs/find \-exec AND parallel"
|
|
.IX Header "DIFFERENCES BETWEEN xargs/find -exec AND parallel"
|
|
\&\fBxargs\fR and \fBfind \-exec\fR offer some of the same possibilites as
|
|
\&\fBparallel\fR.
|
|
.PP
|
|
\&\fBfind \-exec\fR only works on files. So processing other input (such as
|
|
hosts or URLs) will require creating these inputs as files. \fBfind
|
|
\&\-exec\fR has no support for running commands in parallel.
|
|
.PP
|
|
\&\fBxargs\fR deals badly with special characters (such as space, ' and ") unless
|
|
\&\fB\-0\fR is specified. Many input generators are not optimized for using
|
|
\&\fB\s-1NUL\s0\fR as separator but are optimized for \fBnewline\fR as separator. E.g
|
|
\&\fBhead\fR, \fBtail\fR, \fBawk\fR, \fBls\fR, \fBecho\fR, \fBsed\fR, \fBtar \-v\fR, \fBperl\fR
|
|
(\-0 and \e0 instead of \en), \fBlocate\fR (requires using \-0), \fBfind\fR
|
|
(requires using \-print0), \fBgrep\fR (requires user to use \-z or \-Z).
|
|
.PP
|
|
The input \fIcan\fR be fixed for \fBxargs\fR with:
|
|
.PP
|
|
tr '\en' '\e0'
|
|
.PP
|
|
So \fBparallel\fR's newline separation can be emulated with:
|
|
.PP
|
|
cat | tr '\en' '\e0' | xargs \-0 \-n1 \fIcommand\fR
|
|
.PP
|
|
\&\fBxargs\fR can run a given number of jobs in parallel, but has no
|
|
support for running no_of_cpus jobs in parallel.
|
|
.PP
|
|
\&\fBxargs\fR 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.
|
|
.PP
|
|
If no command is given to \fBxargs\fR it defaults to /bin/echo. So the
|
|
\&\fBcat | sh\fR functionality is missing.
|
|
.PP
|
|
Quoting in \fBxargs\fR works like \fB\-q\fR in \fBparallel\fR. Doing \fBls |
|
|
parallel "wc {} \fR> \fB{}.wc"\fR using \fBxargs\fR seems to be impossible.
|
|
.SH "BUGS"
|
|
.IX Header "BUGS"
|
|
Filenames beginning with '\-' can cause some commands to give
|
|
unexpected results, as it will often be interpreted as an option.
|
|
.SH "REPORTING BUGS"
|
|
.IX Header "REPORTING BUGS"
|
|
Report bugs to <bug\-parallel@tange.dk>.
|
|
.SH "AUTHOR"
|
|
.IX Header "AUTHOR"
|
|
Copyright (C) 2007\-10\-18 Ole Tange, http://ole.tange.dk
|
|
.PP
|
|
Copyright (C) 2008\-2009 Ole Tange, http://ole.tange.dk
|
|
.SH "LICENSE"
|
|
.IX Header "LICENSE"
|
|
Copyright (C) 2007\-2009 Free Software Foundation, Inc.
|
|
.PP
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the \s-1GNU\s0 General Public License as published by
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
(at your option) any later version.
|
|
.PP
|
|
This program is distributed in the hope that it will be useful,
|
|
but \s-1WITHOUT\s0 \s-1ANY\s0 \s-1WARRANTY\s0; without even the implied warranty of
|
|
\&\s-1MERCHANTABILITY\s0 or \s-1FITNESS\s0 \s-1FOR\s0 A \s-1PARTICULAR\s0 \s-1PURPOSE\s0. See the
|
|
\&\s-1GNU\s0 General Public License for more details.
|
|
.PP
|
|
You should have received a copy of the \s-1GNU\s0 General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
.SH "DEPENDENCIES"
|
|
.IX Header "DEPENDENCIES"
|
|
\&\fBparallel\fR uses Perl, and the Perl modules Getopt::Std, IPC::Open3,
|
|
Symbol, IO::File, \s-1POSIX\s0, and File::Temp.
|
|
.SH "SEE ALSO"
|
|
.IX Header "SEE ALSO"
|
|
\&\fBfind\fR(1), \fBxargs\fR(1)
|