\input texinfo
@setfilename parallel.info

@documentencoding utf-8

@settitle parallel - build and execute shell command lines from standard input in parallel

@node Top
@top parallel

@menu
* NAME::
* SYNOPSIS::
* DESCRIPTION::
* OPTIONS::
* EXAMPLE@asis{:} Working as xargs -n1. Argument appending::
* EXAMPLE@asis{:} Simple network scanner::
* EXAMPLE@asis{:} Reading arguments from command line::
* EXAMPLE@asis{:} Inserting multiple arguments::
* EXAMPLE@asis{:} Context replace::
* EXAMPLE@asis{:} Compute intensive jobs and substitution::
* EXAMPLE@asis{:} Substitution and redirection::
* EXAMPLE@asis{:} Composed commands::
* EXAMPLE@asis{:} Composed command with multiple input sources::
* EXAMPLE@asis{:} Calling Bash functions::
* EXAMPLE@asis{:} Function tester::
* EXAMPLE@asis{:} Log rotate::
* EXAMPLE@asis{:} Removing file extension when processing files::
* EXAMPLE@asis{:} Removing strings from the argument::
* EXAMPLE@asis{:} Download 24 images for each of the past 30 days::
* EXAMPLE@asis{:} Download world map from NASA::
* EXAMPLE@asis{:} Download Apollo-11 images from NASA using jq::
* EXAMPLE@asis{:} Download video playlist in parallel::
* EXAMPLE@asis{:} Prepend last modified date (ISO8601) to file name::
* EXAMPLE@asis{:} Save output in ISO8601 dirs::
* EXAMPLE@asis{:} Digital clock with "blinking" @asis{:}::
* EXAMPLE@asis{:} Aggregating content of files::
* EXAMPLE@asis{:} Breadth first parallel web crawler/mirrorer::
* EXAMPLE@asis{:} Process files from a tar file while unpacking::
* EXAMPLE@asis{:} Rewriting a for-loop and a while-read-loop::
* EXAMPLE@asis{:} Rewriting nested for-loops::
* EXAMPLE@asis{:} Finding the lowest difference between files::
* EXAMPLE@asis{:} for-loops with column names::
* EXAMPLE@asis{:} All combinations in a list::
* EXAMPLE@asis{:} From a to b and b to c::
* EXAMPLE@asis{:} Count the differences between all files in a dir::
* EXAMPLE@asis{:} Speeding up fast jobs::
* EXAMPLE@asis{:} Using shell variables::
* EXAMPLE@asis{:} Group output lines::
* EXAMPLE@asis{:} Tag output lines::
* EXAMPLE@asis{:} Colorize output::
* EXAMPLE@asis{:} Keep order of output same as order of input::
* EXAMPLE@asis{:} Parallel grep::
* EXAMPLE@asis{:} Grepping n lines for m regular expressions.::
* EXAMPLE@asis{:} Using remote computers::
* EXAMPLE@asis{:} Transferring of files::
* EXAMPLE@asis{:} Distributing work to local and remote computers::
* EXAMPLE@asis{:} Running the same command on remote computers::
* EXAMPLE@asis{:} Using remote computers behind NAT wall::
* EXAMPLE@asis{:} Parallelizing rsync::
* EXAMPLE@asis{:} Use multiple inputs in one command::
* EXAMPLE@asis{:} Use a table as input::
* EXAMPLE@asis{:} Output to database::
* EXAMPLE@asis{:} Output to CSV-file for R::
* EXAMPLE@asis{:} Use XML as input::
* EXAMPLE@asis{:} Run the same command 10 times::
* EXAMPLE@asis{:} Working as cat | sh. Resource inexpensive jobs and evaluation::
* EXAMPLE@asis{:} Processing a big file using more CPUs::
* EXAMPLE@asis{:} Grouping input lines::
* EXAMPLE@asis{:} Running more than 250 jobs workaround::
* EXAMPLE@asis{:} Working as mutex and counting semaphore::
* EXAMPLE@asis{:} Mutex for a script::
* EXAMPLE@asis{:} Start editor with filenames from stdin (standard input)::
* EXAMPLE@asis{:} Running sudo::
* EXAMPLE@asis{:} GNU Parallel as queue system/batch manager::
* EXAMPLE@asis{:} GNU Parallel as dir processor::
* EXAMPLE@asis{:} Locate the missing package::
* QUOTING::
* LIST RUNNING JOBS::
* COMPLETE RUNNING JOBS BUT DO NOT START NEW JOBS::
* ENVIRONMENT VARIABLES::
* DEFAULT PROFILE (CONFIG FILE)::
* PROFILE FILES::
* EXIT STATUS::
* DIFFERENCES BETWEEN GNU Parallel AND ALTERNATIVES::
* BUGS::
* REPORTING BUGS::
* AUTHOR::
* LICENSE::
* DEPENDENCIES::
* SEE ALSO::
@end menu

@node NAME
@chapter NAME

parallel - build and execute shell command lines from standard input
in parallel

@node SYNOPSIS
@chapter SYNOPSIS

@strong{parallel} [options] [@emph{command} [arguments]] < list_of_arguments

@strong{parallel} [options] [@emph{command} [arguments]] ( @strong{:::} arguments |
@strong{:::+} arguments | @strong{::::} argfile(s) | @strong{::::+} argfile(s) ) ...

@strong{parallel} --semaphore [options] @emph{command}

@strong{#!/usr/bin/parallel} --shebang [options] [@emph{command} [arguments]]

@strong{#!/usr/bin/parallel} --shebang-wrap [options] [@emph{command}
[arguments]]

@node DESCRIPTION
@chapter DESCRIPTION

STOP!

Read the @strong{Reader's guide} below if you are new to GNU @strong{parallel}.

GNU @strong{parallel} is a shell tool for executing jobs in parallel using
one or more computers. A job can be 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. A job can also be a command that reads from
a pipe. GNU @strong{parallel} can then split the input into blocks and pipe
a block into each command in parallel.

If you use xargs and tee today you will find GNU @strong{parallel} very easy
to use as GNU @strong{parallel} is written to have the same options as
xargs. If you write loops in shell, you will find GNU @strong{parallel} may
be able to replace most of the loops and make them run faster by
running several jobs in parallel.

GNU @strong{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 @strong{parallel} as input for other
programs.

For each line of input GNU @strong{parallel} will execute @emph{command} with
the line as arguments. If no @emph{command} is given, the line of input is
executed. Several lines will be run in parallel. GNU @strong{parallel} can
often be used as a substitute for @strong{xargs} or @strong{cat | bash}.

@menu
* Reader's guide::
@end menu

@node Reader's guide
@section Reader's guide

If you prefer reading a book buy @strong{GNU Parallel 2018} at
http://www.lulu.com/shop/ole-tange/gnu-parallel-2018/paperback/product-23558902.html
or download it at: https://doi.org/10.5281/zenodo.1146014

Otherwise start by watching the intro videos for a quick introduction:
http://www.youtube.com/playlist?list=PL284C9FF2488BC6D1

Then browse through the @strong{EXAMPLE}s after the list of @strong{OPTIONS} in
@strong{man parallel} (Use @strong{LESS=+/EXAMPLE: man parallel}). That will give
you an idea of what GNU @strong{parallel} is capable of.

If you want to dive even deeper: spend a couple of hours walking
through the tutorial (@strong{man parallel_tutorial}). Your command line
will love you for it.

Finally you may want to look at the rest of the manual (@strong{man
parallel}) if you have special needs not already covered.

If you want to know the design decisions behind GNU @strong{parallel}, try:
@strong{man parallel_design}. This is also a good intro if you intend to
change GNU @strong{parallel}.

@node OPTIONS
@chapter OPTIONS

@table @asis
@item @emph{command}
@anchor{@emph{command}}

Command to execute.  If @emph{command} or the following arguments contain
replacement strings (such as @strong{@{@}}) every instance will be substituted
with the input.

If @emph{command} is given, GNU @strong{parallel} solve the same tasks as
@strong{xargs}. If @emph{command} is not given GNU @strong{parallel} will behave
similar to @strong{cat | sh}.

The @emph{command} must be an executable, a script, a composed command, an
alias, or a function.

@strong{Bash functions}: @strong{export -f} the function first or use @strong{env_parallel}.

@strong{Bash, Csh, or Tcsh aliases}: Use @strong{env_parallel}.

@strong{Zsh, Fish, Ksh, and Pdksh functions and aliases}: Use @strong{env_parallel}.

@item @strong{@{@}}
@anchor{@strong{@{@}}}

Input line. This replacement string will be replaced by a full line
read from the input source. The input source is normally stdin
(standard input), but can also be given with @strong{-a}, @strong{:::}, or
@strong{::::}.

The replacement string @strong{@{@}} can be changed with @strong{-I}.

If the command line contains no replacement strings then @strong{@{@}} will be
appended to the command line.

Replacement strings are normally quoted, so special characters are not
parsed by the shell. The exception is if the command starts with a
replacement string; then the string is not quoted.

@item @strong{@{.@}}
@anchor{@strong{@{.@}}}

Input line without extension. This replacement string will be replaced
by the input with the extension removed. If the input line contains
@strong{.} after the last @strong{/}, the last @strong{.} until the end of the string
will be removed and @strong{@{.@}} will be replaced with the
remaining. E.g. @emph{foo.jpg} becomes @emph{foo}, @emph{subdir/foo.jpg} becomes
@emph{subdir/foo}, @emph{sub.dir/foo.jpg} becomes @emph{sub.dir/foo},
@emph{sub.dir/bar} remains @emph{sub.dir/bar}. If the input line does not
contain @strong{.} it will remain unchanged.

The replacement string @strong{@{.@}} can be changed with @strong{--er}.

To understand replacement strings see @strong{@{@}}.

@item @strong{@{/@}}
@anchor{@strong{@{/@}}}

Basename of input line. This replacement string will be replaced by
the input with the directory part removed.

The replacement string @strong{@{/@}} can be changed with
@strong{--basenamereplace}.

To understand replacement strings see @strong{@{@}}.

@item @strong{@{//@}}
@anchor{@strong{@{//@}}}

Dirname of input line. This replacement string will be replaced by the
dir of the input line. See @strong{dirname}(1).

The replacement string @strong{@{//@}} can be changed with
@strong{--dirnamereplace}.

To understand replacement strings see @strong{@{@}}.

@item @strong{@{/.@}}
@anchor{@strong{@{/.@}}}

Basename of input line without extension. This replacement string will
be replaced by the input with the directory and extension part
removed. It is a combination of @strong{@{/@}} and @strong{@{.@}}.

The replacement string @strong{@{/.@}} can be changed with
@strong{--basenameextensionreplace}.

To understand replacement strings see @strong{@{@}}.

@item @strong{@{#@}}
@anchor{@strong{@{#@}}}

Sequence number of the job to run. This replacement string will be
replaced by the sequence number of the job being run. It contains the
same number as $PARALLEL_SEQ.

The replacement string @strong{@{#@}} can be changed with @strong{--seqreplace}.

To understand replacement strings see @strong{@{@}}.

@item @strong{@{%@}}
@anchor{@strong{@{%@}}}

Job slot number. This replacement string will be replaced by the job's
slot number between 1 and number of jobs to run in parallel. There
will never be 2 jobs running at the same time with the same job slot
number.

The replacement string @strong{@{%@}} can be changed with @strong{--slotreplace}.

To understand replacement strings see @strong{@{@}}.

@item @strong{@{}@emph{n}@strong{@}}
@anchor{@strong{@{}@emph{n}@strong{@}}}

Argument from input source @emph{n} or the @emph{n}'th argument. This
positional replacement string will be replaced by the input from input
source @emph{n} (when used with @strong{-a} or @strong{::::}) or with the @emph{n}'th
argument (when used with @strong{-N}). If @emph{n} is negative it refers to the
@emph{n}'th last argument.

To understand replacement strings see @strong{@{@}}.

@item @strong{@{}@emph{n}.@strong{@}}
@anchor{@strong{@{}@emph{n}.@strong{@}}}

Argument from input source @emph{n} or the @emph{n}'th argument without
extension. It is a combination of @strong{@{}@emph{n}@strong{@}} and @strong{@{.@}}.

This positional replacement string will be replaced by the input from
input source @emph{n} (when used with @strong{-a} or @strong{::::}) or with the
@emph{n}'th argument (when used with @strong{-N}). The input will have the
extension removed.

To understand positional replacement strings see @strong{@{}@emph{n}@strong{@}}.

@item @strong{@{}@emph{n}/@strong{@}}
@anchor{@strong{@{}@emph{n}/@strong{@}}}

Basename of argument from input source @emph{n} or the @emph{n}'th argument.
It is a combination of @strong{@{}@emph{n}@strong{@}} and @strong{@{/@}}.

This positional replacement string will be replaced by the input from
input source @emph{n} (when used with @strong{-a} or @strong{::::}) or with the
@emph{n}'th argument (when used with @strong{-N}). The input will have the
directory (if any) removed.

To understand positional replacement strings see @strong{@{}@emph{n}@strong{@}}.

@item @strong{@{}@emph{n}//@strong{@}}
@anchor{@strong{@{}@emph{n}//@strong{@}}}

Dirname of argument from input source @emph{n} or the @emph{n}'th argument.
It is a combination of @strong{@{}@emph{n}@strong{@}} and @strong{@{//@}}.

This positional replacement string will be replaced by the dir of the
input from input source @emph{n} (when used with @strong{-a} or @strong{::::}) or with
the @emph{n}'th argument (when used with @strong{-N}). See @strong{dirname}(1).

To understand positional replacement strings see @strong{@{}@emph{n}@strong{@}}.

@item @strong{@{}@emph{n}/.@strong{@}}
@anchor{@strong{@{}@emph{n}/.@strong{@}}}

Basename of argument from input source @emph{n} or the @emph{n}'th argument
without extension.  It is a combination of @strong{@{}@emph{n}@strong{@}}, @strong{@{/@}}, and
@strong{@{.@}}.

This positional replacement string will be replaced by the input from
input source @emph{n} (when used with @strong{-a} or @strong{::::}) or with the
@emph{n}'th argument (when used with @strong{-N}). The input will have the
directory (if any) and extension removed.

To understand positional replacement strings see @strong{@{}@emph{n}@strong{@}}.

@item @strong{@{=}@emph{perl expression}@strong{=@}}
@anchor{@strong{@{=}@emph{perl expression}@strong{=@}}}

Replace with calculated @emph{perl expression}. @strong{$_} will contain the
same as @strong{@{@}}. After evaluating @emph{perl expression} @strong{$_} will be used
as the value. It is recommended to only change $_ but you have full
access to all of GNU @strong{parallel}'s internal functions and data
structures. A few convenience functions and data structures have been
made:

@table @asis
@item @strong{Q(}@emph{string}@strong{)}
@anchor{@strong{Q(}@emph{string}@strong{)}}

shell quote a string

@item @strong{pQ(}@emph{string}@strong{)}
@anchor{@strong{pQ(}@emph{string}@strong{)}}

perl quote a string

@item @strong{total_jobs()}
@anchor{@strong{total_jobs()}}

number of jobs in total

@item @strong{slot()}
@anchor{@strong{slot()}}

slot number of job

@item @strong{seq()}
@anchor{@strong{seq()}}

sequence number of job

@item @strong{@@arg}
@anchor{@strong{@@arg}}

the arguments

@end table

Example:

@verbatim
  seq 10 | parallel echo {} + 1 is {= '$_++' =}
  parallel csh -c {= '$_="mkdir ".Q($_)' =} ::: '12" dir'
  seq 50 | parallel echo job {#} of {= '$_=total_jobs()' =}
@end verbatim

See also: @strong{--rpl} @strong{--parens}

@item @strong{@{=}@emph{n} @emph{perl expression}@strong{=@}}
@anchor{@strong{@{=}@emph{n} @emph{perl expression}@strong{=@}}}

Positional equivalent to @strong{@{=perl expression=@}}. To understand
positional replacement strings see @strong{@{}@emph{n}@strong{@}}.

See also: @strong{@{=perl expression=@}} @strong{@{}@emph{n}@strong{@}}.

@item @strong{:::} @emph{arguments}
@anchor{@strong{:::} @emph{arguments}}

Use arguments from the command line as input source instead of stdin
(standard input). Unlike other options for GNU @strong{parallel} @strong{:::} is
placed after the @emph{command} and before the arguments.

The following are equivalent:

@verbatim
  (echo file1; echo file2) | parallel gzip
  parallel gzip ::: file1 file2
  parallel gzip {} ::: file1 file2
  parallel --arg-sep ,, gzip {} ,, file1 file2
  parallel --arg-sep ,, gzip ,, file1 file2
  parallel ::: "gzip file1" "gzip file2"
@end verbatim

To avoid treating @strong{:::} as special use @strong{--arg-sep} to set the
argument separator to something else. See also @strong{--arg-sep}.

If multiple @strong{:::} are given, each group will be treated as an input
source, and all combinations of input sources will be
generated. E.g. ::: 1 2 ::: a b c will result in the combinations
(1,a) (1,b) (1,c) (2,a) (2,b) (2,c). This is useful for replacing
nested for-loops.

@strong{:::} and @strong{::::} can be mixed. So these are equivalent:

@verbatim
  parallel echo {1} {2} {3} ::: 6 7 ::: 4 5 ::: 1 2 3
  parallel echo {1} {2} {3} :::: <(seq 6 7) <(seq 4 5) \
    :::: <(seq 1 3)
  parallel -a <(seq 6 7) echo {1} {2} {3} :::: <(seq 4 5) \
    :::: <(seq 1 3)
  parallel -a <(seq 6 7) -a <(seq 4 5) echo {1} {2} {3} \
    ::: 1 2 3
  seq 6 7 | parallel -a - -a <(seq 4 5) echo {1} {2} {3} \
    ::: 1 2 3
  seq 4 5 | parallel echo {1} {2} {3} :::: <(seq 6 7) - \
    ::: 1 2 3
@end verbatim

@item @strong{:::+} @emph{arguments}
@anchor{@strong{:::+} @emph{arguments}}

Like @strong{:::} but linked like @strong{--link} to the previous input source.

Contrary to @strong{--link}, values do not wrap: The shortest input source
determines the length.

Example:

@verbatim
  parallel echo ::: a b c :::+ 1 2 3 ::: X Y :::+ 11 22
@end verbatim

@item @strong{::::} @emph{argfiles}
@anchor{@strong{::::} @emph{argfiles}}

Another way to write @strong{-a} @emph{argfile1} @strong{-a} @emph{argfile2} ...

@strong{:::} and @strong{::::} can be mixed.

See @strong{-a}, @strong{:::} and @strong{--link}.

@item @strong{::::+} @emph{argfiles}
@anchor{@strong{::::+} @emph{argfiles}}

Like @strong{::::} but linked like @strong{--link} to the previous input source.

Contrary to @strong{--link}, values do not wrap: The shortest input source
determines the length.

@item @strong{--null}
@anchor{@strong{--null}}

@item @strong{-0}
@anchor{@strong{-0}}

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).

@item @strong{--arg-file} @emph{input-file}
@anchor{@strong{--arg-file} @emph{input-file}}

@item @strong{-a} @emph{input-file}
@anchor{@strong{-a} @emph{input-file}}

Use @emph{input-file} as input source. If you use this option, stdin
(standard input) is given to the first process run.  Otherwise, stdin
(standard input) is redirected from /dev/null.

If multiple @strong{-a} are given, each @emph{input-file} will be treated as an
input source, and all combinations of input sources will be
generated. E.g. The file @strong{foo} contains @strong{1 2}, the file @strong{bar}
contains @strong{a b c}.  @strong{-a foo} @strong{-a bar} will result in the combinations
(1,a) (1,b) (1,c) (2,a) (2,b) (2,c). This is useful for replacing
nested for-loops.

See also @strong{--link} and @strong{@{}@emph{n}@strong{@}}.

@item @strong{--arg-file-sep} @emph{sep-str}
@anchor{@strong{--arg-file-sep} @emph{sep-str}}

Use @emph{sep-str} instead of @strong{::::} as separator string between command
and argument files. Useful if @strong{::::} is used for something else by the
command.

See also: @strong{::::}.

@item @strong{--arg-sep} @emph{sep-str}
@anchor{@strong{--arg-sep} @emph{sep-str}}

Use @emph{sep-str} instead of @strong{:::} as separator string. Useful if @strong{:::}
is used for something else by the command.

Also useful if you command uses @strong{:::} but you still want to read
arguments from stdin (standard input): Simply change @strong{--arg-sep} to a
string that is not in the command line.

See also: @strong{:::}.

@item @strong{--bar}
@anchor{@strong{--bar}}

Show progress as a progress bar. In the bar is shown: % of jobs
completed, estimated seconds left, and number of jobs started.

It is compatible with @strong{zenity}:

@verbatim
  seq 1000 | parallel -j30 --bar '(echo {};sleep 0.1)' \
    2> >(zenity --progress --auto-kill) | wc
@end verbatim

@item @strong{--basefile} @emph{file}
@anchor{@strong{--basefile} @emph{file}}

@item @strong{--bf} @emph{file}
@anchor{@strong{--bf} @emph{file}}

@emph{file} will be transferred to each sshlogin before a job is
started. It will be removed if @strong{--cleanup} is active. The file may be
a script to run or some common base data needed for the job.
Multiple @strong{--bf} can be specified to transfer more basefiles. The
@emph{file} will be transferred the same way as @strong{--transferfile}.

@item @strong{--basenamereplace} @emph{replace-str}
@anchor{@strong{--basenamereplace} @emph{replace-str}}

@item @strong{--bnr} @emph{replace-str}
@anchor{@strong{--bnr} @emph{replace-str}}

Use the replacement string @emph{replace-str} instead of @strong{@{/@}} for
basename of input line.

@item @strong{--basenameextensionreplace} @emph{replace-str}
@anchor{@strong{--basenameextensionreplace} @emph{replace-str}}

@item @strong{--bner} @emph{replace-str}
@anchor{@strong{--bner} @emph{replace-str}}

Use the replacement string @emph{replace-str} instead of @strong{@{/.@}} for basename of input line without extension.

@item @strong{--bg}
@anchor{@strong{--bg}}

Run command in background thus GNU @strong{parallel} will not wait for
completion of the command before exiting. This is the default if
@strong{--semaphore} is set.

See also: @strong{--fg}, @strong{man sem}.

Implies @strong{--semaphore}.

@item @strong{--bibtex}
@anchor{@strong{--bibtex}}

@item @strong{--citation}
@anchor{@strong{--citation}}

Print the citation notice and BibTeX entry for GNU @strong{parallel},
silence citation notice for all future runs, and exit. It will not run
any commands.

If it is impossible for you to run @strong{--citation} you can instead use
@strong{--will-cite}, which will run commands, but which will only silence
the citation notice for this single run.

If you use @strong{--will-cite} in scripts to be run by others you are
making it harder for others to see the citation notice.  The
development of GNU @strong{parallel} is indirectly financed through
citations, so if your users do not know they should cite then you are
making it harder to finance development. However, if you pay 10000
EUR, you have done your part to finance future development and should
feel free to use @strong{--will-cite} in scripts.

If you do not want to help financing future development by letting
other users see the citation notice or by paying, then please use
another tool instead of GNU @strong{parallel}. You can find some of the
alternatives in @strong{man parallel_alternatives}.

@item @strong{--block} @emph{size}
@anchor{@strong{--block} @emph{size}}

@item @strong{--block-size} @emph{size}
@anchor{@strong{--block-size} @emph{size}}

Size of block in bytes to read at a time. The @emph{size} can be postfixed
with K, M, G, T, P, E, k, m, g, t, p, or e which would multiply the
size with 1024, 1048576, 1073741824, 1099511627776, 1125899906842624,
1152921504606846976, 1000, 1000000, 1000000000, 1000000000000,
1000000000000000, or 1000000000000000000 respectively.

GNU @strong{parallel} tries to meet the block size but can be off by the
length of one record. For performance reasons @emph{size} should be bigger
than a two records. GNU @strong{parallel} will warn you and automatically
increase the size if you choose a @emph{size} that is too small.

If you use @strong{-N}, @strong{--block-size} should be bigger than N+1 records.

@emph{size} defaults to 1M.

When using @strong{--pipepart} a negative block size is not interpreted as a
blocksize but as the number of blocks each jobslot should have. So
this will run 10*5 = 50 jobs in total:

@verbatim
  parallel --pipepart -a myfile --block -10 -j5 wc
@end verbatim

This is an efficient alternative to @strong{--roundrobin} because data is
never read by GNU @strong{parallel}, but you can still have very few
jobslots process a large amount of data.

See @strong{--pipe} and @strong{--pipepart} for use of this.

@item @strong{--cat}
@anchor{@strong{--cat}}

Create a temporary file with content. Normally @strong{--pipe}/@strong{--pipepart}
will give data to the program on stdin (standard input). With @strong{--cat}
GNU @strong{parallel} will create a temporary file with the name in @strong{@{@}}, so
you can do: @strong{parallel --pipe --cat wc @{@}}.

Implies @strong{--pipe} unless @strong{--pipepart} is used.

See also @strong{--fifo}.

@item @strong{--cleanup}
@anchor{@strong{--cleanup}}

Remove transferred files. @strong{--cleanup} will remove the transferred
files on the remote computer after processing is done.

@verbatim
  find log -name '*gz' | parallel \
    --sshlogin server.example.com --transferfile {} \
    --return {.}.bz2 --cleanup "zcat {} | bzip -9 >{.}.bz2"
@end verbatim

With @strong{--transferfile @{@}} the file transferred to the remote computer
will be removed on the remote computer.  Directories created will not
be removed - even if they are empty.

With @strong{--return} the file transferred from the remote computer will be
removed on the remote computer.  Directories created will not be
removed - even if they are empty.

@strong{--cleanup} is ignored when not used with @strong{--transferfile} or
@strong{--return}.

@item @strong{--colsep} @emph{regexp}
@anchor{@strong{--colsep} @emph{regexp}}

@item @strong{-C} @emph{regexp}
@anchor{@strong{-C} @emph{regexp}}

Column separator. The input will be treated as a table with @emph{regexp}
separating the columns. The n'th column can be accessed using
@strong{@{}@emph{n}@strong{@}} or @strong{@{}@emph{n}.@strong{@}}. E.g. @strong{@{3@}} is the 3rd column.

If there are more input sources, each input source will be separated,
but the columns from each input source will be linked (see @strong{--link}).

@verbatim
  parallel --colsep '-' echo {4} {3} {2} {1} \
    ::: A-B C-D ::: e-f g-h
@end verbatim

@strong{--colsep} implies @strong{--trim rl}, which can be overridden with
@strong{--trim n}.

@emph{regexp} is a Perl Regular Expression:
http://perldoc.perl.org/perlre.html

@item @strong{--compress}
@anchor{@strong{--compress}}

Compress temporary files. If the output is big and very compressible
this will take up less disk space in $TMPDIR and possibly be faster
due to less disk I/O.

GNU @strong{parallel} will try @strong{pzstd}, @strong{lbzip2}, @strong{pbzip2}, @strong{zstd},
@strong{pigz}, @strong{lz4}, @strong{lzop}, @strong{plzip}, @strong{lzip}, @strong{lrz}, @strong{gzip}, @strong{pxz},
@strong{lzma}, @strong{bzip2}, @strong{xz}, @strong{clzip}, in that order, and use the first
available.

@item @strong{--compress-program} @emph{prg}
@anchor{@strong{--compress-program} @emph{prg}}

@item @strong{--decompress-program} @emph{prg}
@anchor{@strong{--decompress-program} @emph{prg}}

Use @emph{prg} for (de)compressing temporary files. It is assumed that @emph{prg
-dc} will decompress stdin (standard input) to stdout (standard
output) unless @strong{--decompress-program} is given.

@item @strong{--csv}
@anchor{@strong{--csv}}

Treat input as CSV-format. @strong{--colsep} sets the field delimiter. It
works very much like @strong{--colsep} except it deals correctly with
quoting:

@verbatim
   echo '"1 big, 2 small","2""x4"" plank",12.34' |
     parallel --csv echo {1} of {2} at {3}
@end verbatim

Even quoted newlines are parsed correctly:

@verbatim
   (echo '"Start of field 1 with newline'
    echo 'Line 2 in field 1";value 2') |
     parallel --csv --colsep ';' echo Field 1: {1} Field 2: {2}
@end verbatim

When used with @strong{--pipe} only pass full CSV-records.

@item @strong{--delimiter} @emph{delim}
@anchor{@strong{--delimiter} @emph{delim}}

@item @strong{-d} @emph{delim}
@anchor{@strong{-d} @emph{delim}}

Input items are terminated by @emph{delim}.  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. The
specified delimiter may be characters, C-style character escapes such
as \n, or octal or hexadecimal escape codes.  Octal and hexadecimal
escape codes are understood as for the printf command.  Multibyte
characters are not supported.

@item @strong{--dirnamereplace} @emph{replace-str}
@anchor{@strong{--dirnamereplace} @emph{replace-str}}

@item @strong{--dnr} @emph{replace-str}
@anchor{@strong{--dnr} @emph{replace-str}}

Use the replacement string @emph{replace-str} instead of @strong{@{//@}} for
dirname of input line.

@item @strong{-E} @emph{eof-str}
@anchor{@strong{-E} @emph{eof-str}}

Set the end of file string to @emph{eof-str}.  If the end of file string
occurs as a line of input, the rest of the input is not read.  If
neither @strong{-E} nor @strong{-e} is used, no end of file string is used.

@item @strong{--delay} @emph{mytime}
@anchor{@strong{--delay} @emph{mytime}}

Delay starting next job by @emph{mytime}. GNU @strong{parallel} will pause
@emph{mytime} after starting each job. @emph{mytime} is normally in seconds,
but can be floats postfixed with @strong{s}, @strong{m}, @strong{h}, or @strong{d} which would
multiply the float by 1, 60, 3600, or 86400. Thus these are
equivalent: @strong{--delay 100000} and @strong{--delay 1d3.5h16.6m4s}.

@item @strong{--dry-run}
@anchor{@strong{--dry-run}}

Print the job to run on stdout (standard output), but do not run the
job. Use @strong{-v -v} to include the wrapping that GNU Parallel generates
(for remote jobs, @strong{--tmux}, @strong{--nice}, @strong{--pipe}, @strong{--pipepart},
@strong{--fifo} and @strong{--cat}). Do not count on this literally, though, as the
job may be scheduled on another computer or the local computer if : is
in the list.

@item @strong{--eof}[=@emph{eof-str}]
@anchor{@strong{--eof}[=@emph{eof-str}]}

@item @strong{-e}[@emph{eof-str}]
@anchor{@strong{-e}[@emph{eof-str}]}

This option is a synonym for the @strong{-E} option.  Use @strong{-E} instead,
because it is POSIX compliant for @strong{xargs} while this option is not.
If @emph{eof-str} is omitted, there is no end of file string.  If neither
@strong{-E} nor @strong{-e} is used, no end of file string is used.

@item @strong{--embed}
@anchor{@strong{--embed}}

Embed GNU @strong{parallel} in a shell script. If you need to distribute your
script to someone who does not want to install GNU @strong{parallel} you can
embed GNU @strong{parallel} in your own shell script:

@verbatim
  parallel --embed > new_script
@end verbatim

After which you add your code at the end of @strong{new_script}. This is tested
on @strong{ash}, @strong{bash}, @strong{dash}, @strong{ksh}, @strong{sh}, and @strong{zsh}.

@item @strong{--env} @emph{var}
@anchor{@strong{--env} @emph{var}}

Copy environment variable @emph{var}. This will copy @emph{var} to the
environment that the command is run in. This is especially useful for
remote execution.

In Bash @emph{var} can also be a Bash function - just remember to @strong{export
-f} the function, see @strong{command}.

The variable '_' is special. It will copy all exported environment
variables except for the ones mentioned in ~/.parallel/ignored_vars.

To copy the full environment (both exported and not exported
variables, arrays, and functions) use @strong{env_parallel}.

See also: @strong{--record-env}, @strong{--session}.

@item @strong{--eta}
@anchor{@strong{--eta}}

Show the estimated number of seconds before finishing. This forces GNU
@strong{parallel} to read all jobs before starting to find the number of
jobs. GNU @strong{parallel} normally only reads the next job to run.

The estimate is based on the runtime of finished jobs, so the first
estimate will only be shown when the first job has finished.

Implies @strong{--progress}.

See also: @strong{--bar}, @strong{--progress}.

@item @strong{--fg}
@anchor{@strong{--fg}}

Run command in foreground.

With @strong{--tmux} and @strong{--tmuxpane} GNU @strong{parallel} will start @strong{tmux} in
the foreground.

With @strong{--semaphore} GNU @strong{parallel} will run the command in the
foreground (opposite @strong{--bg}), and wait for completion of the command
before exiting.

See also @strong{--bg}, @strong{man sem}.

@item @strong{--fifo}
@anchor{@strong{--fifo}}

Create a temporary fifo with content. Normally @strong{--pipe} and
@strong{--pipepart} will give data to the program on stdin (standard
input). With @strong{--fifo} GNU @strong{parallel} will create a temporary fifo
with the name in @strong{@{@}}, so you can do: @strong{parallel --pipe --fifo wc @{@}}.

Beware: If data is not read from the fifo, the job will block forever.

Implies @strong{--pipe} unless @strong{--pipepart} is used.

See also @strong{--cat}.

@item @strong{--filter-hosts}
@anchor{@strong{--filter-hosts}}

Remove down hosts. For each remote host: check that login through ssh
works. If not: do not use this host.

For performance reasons, this check is performed only at the start and
every time @strong{--sshloginfile} is changed. If an host goes down after
the first check, it will go undetected until @strong{--sshloginfile} is
changed; @strong{--retries} can be used to mitigate this.

Currently you can @emph{not} put @strong{--filter-hosts} in a profile,
$PARALLEL, /etc/parallel/config or similar. This is because GNU
@strong{parallel} uses GNU @strong{parallel} to compute this, so you will get an
infinite loop. This will likely be fixed in a later release.

@item @strong{--gnu}
@anchor{@strong{--gnu}}

Behave like GNU @strong{parallel}. This option historically took precedence
over @strong{--tollef}. The @strong{--tollef} option is now retired, and therefore
may not be used. @strong{--gnu} is kept for compatibility.

@item @strong{--group}
@anchor{@strong{--group}}

Group output. Output from each job is grouped together and is only
printed when the command is finished. Stdout (standard output) first
followed by stderr (standard error).

This takes in the order of 0.5ms per job and depends on the speed of
your disk for larger output. It can be disabled with @strong{-u}, but this
means output from different commands can get mixed.

@strong{--group} is the default. Can be reversed with @strong{-u}.

See also: @strong{--line-buffer} @strong{--ungroup}

@item @strong{--help}
@anchor{@strong{--help}}

@item @strong{-h}
@anchor{@strong{-h}}

Print a summary of the options to GNU @strong{parallel} and exit.

@item @strong{--halt-on-error} @emph{val}
@anchor{@strong{--halt-on-error} @emph{val}}

@item @strong{--halt} @emph{val}
@anchor{@strong{--halt} @emph{val}}

When should GNU @strong{parallel} terminate? In some situations it makes no
sense to run all jobs. GNU @strong{parallel} should simply give up as soon
as a condition is met.

@emph{val} defaults to @strong{never}, which runs all jobs no matter what.

@emph{val} can also take on the form of @emph{when},@emph{why}.

@emph{when} can be 'now' which means kill all running jobs and halt
immediately, or it can be 'soon' which means wait for all running jobs
to complete, but start no new jobs.

@emph{why} can be 'fail=X', 'fail=Y%', 'success=X', 'success=Y%',
'done=X', or 'done=Y%' where X is the number of jobs that has to fail,
succeed, or be done before halting, and Y is the percentage of jobs
that has to fail, succeed, or be done before halting.

Example:

@table @asis
@item --halt now,fail=1
@anchor{--halt now@comma{}fail=1}

exit when the first job fails. Kill running jobs.

@item --halt soon,fail=3
@anchor{--halt soon@comma{}fail=3}

exit when 3 jobs fail, but wait for running jobs to complete.

@item --halt soon,fail=3%
@anchor{--halt soon@comma{}fail=3%}

exit when 3% of the jobs have failed, but wait for running jobs to complete.

@item --halt now,success=1
@anchor{--halt now@comma{}success=1}

exit when a job succeeds. Kill running jobs.

@item --halt soon,success=3
@anchor{--halt soon@comma{}success=3}

exit when 3 jobs succeeds, but wait for running jobs to complete.

@item --halt now,success=3%
@anchor{--halt now@comma{}success=3%}

exit when 3% of the jobs have succeeded. Kill running jobs.

@item --halt now,done=1
@anchor{--halt now@comma{}done=1}

exit when one of the jobs finishes. Kill running jobs.

@item --halt soon,done=3
@anchor{--halt soon@comma{}done=3}

exit when 3 jobs finishes, but wait for running jobs to complete.

@item --halt now,done=3%
@anchor{--halt now@comma{}done=3%}

exit when 3% of the jobs have finished. Kill running jobs.

@end table

For backwards compatibility these also work:

@table @asis
@item 0
@anchor{0}

never

@item 1
@anchor{1}

soon,fail=1

@item 2
@anchor{2}

now,fail=1

@item -1
@anchor{-1}

soon,success=1

@item -2
@anchor{-2}

now,success=1

@item 1-99%
@anchor{1-99%}

soon,fail=1-99%

@end table

@item @strong{--header} @emph{regexp}
@anchor{@strong{--header} @emph{regexp}}

Use regexp as header. For normal usage the matched header (typically
the first line: @strong{--header '.*\n'}) will be split using @strong{--colsep}
(which will default to '\t') and column names can be used as
replacement variables: @strong{@{column name@}}, @strong{@{column name/@}}, @strong{@{column
name//@}}, @strong{@{column name/.@}}, @strong{@{column name.@}}, @strong{@{=column name perl
expression =@}}, ..

For @strong{--pipe} the matched header will be prepended to each output.

@strong{--header :} is an alias for @strong{--header '.*\n'}.

If @emph{regexp} is a number, it is a fixed number of lines.

@item @strong{--hostgroups}
@anchor{@strong{--hostgroups}}

@item @strong{--hgrp}
@anchor{@strong{--hgrp}}

Enable hostgroups on arguments. If an argument contains '@@' the string
after '@@' will be removed and treated as a list of hostgroups on which
this job is allowed to run. If there is no @strong{--sshlogin} with a
corresponding group, the job will run on any hostgroup.

Example:

@verbatim
  parallel --hostgroups \
    --sshlogin @grp1/myserver1 -S @grp1+grp2/myserver2 \
    --sshlogin @grp3/myserver3 \
    echo ::: my_grp1_arg@grp1 arg_for_grp2@grp2 third@grp1+grp3
@end verbatim

@strong{my_grp1_arg} may be run on either @strong{myserver1} or @strong{myserver2},
@strong{third} may be run on either @strong{myserver1} or @strong{myserver3},
but @strong{arg_for_grp2} will only be run on @strong{myserver2}.

See also: @strong{--sshlogin}.

@item @strong{-I} @emph{replace-str}
@anchor{@strong{-I} @emph{replace-str}}

Use the replacement string @emph{replace-str} instead of @strong{@{@}}.

@item @strong{--replace}[=@emph{replace-str}]
@anchor{@strong{--replace}[=@emph{replace-str}]}

@item @strong{-i}[@emph{replace-str}]
@anchor{@strong{-i}[@emph{replace-str}]}

This option is a synonym for @strong{-I}@emph{replace-str} if @emph{replace-str} is
specified, and for @strong{-I @{@}} otherwise.  This option is deprecated;
use @strong{-I} instead.

@item @strong{--joblog} @emph{logfile}
@anchor{@strong{--joblog} @emph{logfile}}

Logfile for executed jobs. Save a list of the executed jobs to
@emph{logfile} in the following TAB separated format: sequence number,
sshlogin, start time as seconds since epoch, run time in seconds,
bytes in files transferred, bytes in files returned, exit status,
signal, and command run.

For @strong{--pipe} bytes transferred and bytes returned are number of input
and output of bytes.

If @strong{logfile} is prepended with '+' log lines will be appended to the
logfile.

To convert the times into ISO-8601 strict do:

@verbatim
  cat logfile | perl -a -F"\t" -ne \
    'chomp($F[2]=`date -d \@$F[2] +%FT%T`); print join("\t",@F)'
@end verbatim

If the host is long, you can use @strong{column -t} to pretty print it:

@verbatim
  cat joblog | column -t
@end verbatim

See also @strong{--resume} @strong{--resume-failed}.

@item @strong{--jobs} @emph{N}
@anchor{@strong{--jobs} @emph{N}}

@item @strong{-j} @emph{N}
@anchor{@strong{-j} @emph{N}}

@item @strong{--max-procs} @emph{N}
@anchor{@strong{--max-procs} @emph{N}}

@item @strong{-P} @emph{N}
@anchor{@strong{-P} @emph{N}}

Number of jobslots on each machine. Run up to N jobs in parallel.  0
means as many as possible. Default is 100% which will run one job per
CPU on each machine.

If @strong{--semaphore} is set, the default is 1 thus making a mutex.

@item @strong{--jobs} @emph{+N}
@anchor{@strong{--jobs} @emph{+N}}

@item @strong{-j} @emph{+N}
@anchor{@strong{-j} @emph{+N}}

@item @strong{--max-procs} @emph{+N}
@anchor{@strong{--max-procs} @emph{+N}}

@item @strong{-P} @emph{+N}
@anchor{@strong{-P} @emph{+N}}

Add N to the number of CPUs.  Run this many jobs in parallel.  See
also @strong{--use-cores-instead-of-threads} and
@strong{--use-sockets-instead-of-threads}.

@item @strong{--jobs} @emph{-N}
@anchor{@strong{--jobs} @emph{-N}}

@item @strong{-j} @emph{-N}
@anchor{@strong{-j} @emph{-N}}

@item @strong{--max-procs} @emph{-N}
@anchor{@strong{--max-procs} @emph{-N}}

@item @strong{-P} @emph{-N}
@anchor{@strong{-P} @emph{-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.  See also
@strong{--use-cores-instead-of-threads} and
@strong{--use-sockets-instead-of-threads}.

@item @strong{--jobs} @emph{N}%
@anchor{@strong{--jobs} @emph{N}%}

@item @strong{-j} @emph{N}%
@anchor{@strong{-j} @emph{N}%}

@item @strong{--max-procs} @emph{N}%
@anchor{@strong{--max-procs} @emph{N}%}

@item @strong{-P} @emph{N}%
@anchor{@strong{-P} @emph{N}%}

Multiply N% with the number of CPUs.  Run this many jobs in
parallel. See also @strong{--use-cores-instead-of-threads} and
@strong{--use-sockets-instead-of-threads}.

@item @strong{--jobs} @emph{procfile}
@anchor{@strong{--jobs} @emph{procfile}}

@item @strong{-j} @emph{procfile}
@anchor{@strong{-j} @emph{procfile}}

@item @strong{--max-procs} @emph{procfile}
@anchor{@strong{--max-procs} @emph{procfile}}

@item @strong{-P} @emph{procfile}
@anchor{@strong{-P} @emph{procfile}}

Read parameter from file. Use the content of @emph{procfile} as parameter
for @emph{-j}. E.g. @emph{procfile} could contain the string 100% or +2 or
10. If @emph{procfile} is changed when a job completes, @emph{procfile} is
read again and the new number of jobs is computed. If the number is
lower than before, running jobs will be allowed to finish but new jobs
will not be started until the wanted number of jobs has been reached.
This makes it possible to change the number of simultaneous running
jobs while GNU @strong{parallel} is running.

@item @strong{--keep-order}
@anchor{@strong{--keep-order}}

@item @strong{-k}
@anchor{@strong{-k}}

Keep sequence of output same as the order of input. Normally the
output of a job will be printed as soon as the job completes. Try this
to see the difference:

@verbatim
  parallel -j4 sleep {}\; echo {} ::: 2 1 4 3
  parallel -j4 -k sleep {}\; echo {} ::: 2 1 4 3
@end verbatim

If used with @strong{--onall} or @strong{--nonall} the output will grouped by
sshlogin in sorted order.

If used with @strong{--pipe --roundrobin} and the same input, the jobslots
will get the same blocks in the same order in every run.

@strong{-k} only affects the order in which the output is printed - not the
order in which jobs are run.

@item @strong{-L} @emph{recsize}
@anchor{@strong{-L} @emph{recsize}}

When used with @strong{--pipe}: Read records of @emph{recsize}.

When used otherwise: Use at most @emph{recsize} nonblank input lines per
command line.  Trailing blanks cause an input line to be logically
continued on the next input line.

@strong{-L 0} means read one line, but insert 0 arguments on the command
line.

Implies @strong{-X} unless @strong{-m}, @strong{--xargs}, or @strong{--pipe} is set.

@item @strong{--max-lines}[=@emph{recsize}]
@anchor{@strong{--max-lines}[=@emph{recsize}]}

@item @strong{-l}[@emph{recsize}]
@anchor{@strong{-l}[@emph{recsize}]}

When used with @strong{--pipe}: Read records of @emph{recsize} lines.

When used otherwise: Synonym for the @strong{-L} option.  Unlike @strong{-L}, the
@emph{recsize} argument is optional.  If @emph{recsize} is not specified,
it defaults to one.  The @strong{-l} option is deprecated since the POSIX
standard specifies @strong{-L} instead.

@strong{-l 0} is an alias for @strong{-l 1}.

Implies @strong{-X} unless @strong{-m}, @strong{--xargs}, or @strong{--pipe} is set.

@item @strong{--limit} "@emph{command} @emph{args}"
@anchor{@strong{--limit} "@emph{command} @emph{args}"}

Dynamic job limit. Before starting a new job run @emph{command} with
@emph{args}. The exit value of @emph{command} determines what GNU @strong{parallel}
will do:

@table @asis
@item 0
@anchor{0 1}

Below limit. Start another job.

@item 1
@anchor{1 1}

Over limit. Start no jobs.

@item 2
@anchor{2 1}

Way over limit. Kill the youngest job.

@end table

You can use any shell command. There are 3 predefined commands:

@table @asis
@item "io @emph{n}"
@anchor{"io @emph{n}"}

Limit for I/O. The amount of disk I/O will be computed as a value
0-100, where 0 is no I/O and 100 is at least one disk is 100%
saturated.

@item "load @emph{n}"
@anchor{"load @emph{n}"}

Similar to @strong{--load}.

@item "mem @emph{n}"
@anchor{"mem @emph{n}"}

Similar to @strong{--memfree}.

@end table

@item @strong{--line-buffer}
@anchor{@strong{--line-buffer}}

@item @strong{--lb}
@anchor{@strong{--lb}}

Buffer output on line basis. @strong{--group} will keep the output together
for a whole job. @strong{--ungroup} allows output to mixup with half a line
coming from one job and half a line coming from another
job. @strong{--line-buffer} fits between these two: GNU @strong{parallel} will
print a full line, but will allow for mixing lines of different jobs.

@strong{--line-buffer} takes more CPU power than both @strong{--group} and
@strong{--ungroup}, but can be much faster than @strong{--group} if the CPU is not
the limiting factor.

Normally @strong{--line-buffer} does not buffer on disk, and can thus
process an infinite amount of data, but it will buffer on disk when
combined with: @strong{--keep-order}, @strong{--results}, @strong{--compress}, and
@strong{--files}. This will make it as slow as @strong{--group} and will limit
output to the available disk space.

With @strong{--keep-order} @strong{--line-buffer} will output lines from the first
job while it is running, then lines from the second job while that is
running. It will buffer full lines, but jobs will not mix. Compare:

@verbatim
  parallel -j0 'echo {};sleep {};echo {}' ::: 1 3 2 4
  parallel -j0 --lb 'echo {};sleep {};echo {}' ::: 1 3 2 4
  parallel -j0 -k --lb 'echo {};sleep {};echo {}' ::: 1 3 2 4
@end verbatim

See also: @strong{--group} @strong{--ungroup}

@item @strong{--xapply}
@anchor{@strong{--xapply}}

@item @strong{--link}
@anchor{@strong{--link}}

Link input sources. Read multiple input sources like @strong{xapply}. If
multiple input sources are given, one argument will be read from each
of the input sources. The arguments can be accessed in the command as
@strong{@{1@}} .. @strong{@{}@emph{n}@strong{@}}, so @strong{@{1@}} will be a line from the first input
source, and @strong{@{6@}} will refer to the line with the same line number
from the 6th input source.

Compare these two:

@verbatim
  parallel echo {1} {2} ::: 1 2 3 ::: a b c
  parallel --link echo {1} {2} ::: 1 2 3 ::: a b c
@end verbatim

Arguments will be recycled if one input source has more arguments than the others:

@verbatim
  parallel --link echo {1} {2} {3} \
    ::: 1 2 ::: I II III ::: a b c d e f g
@end verbatim

See also @strong{--header}, @strong{:::+}, @strong{::::+}.

@item @strong{--load} @emph{max-load}
@anchor{@strong{--load} @emph{max-load}}

Do not start new jobs on a given computer unless the number of running
processes on the computer is less than @emph{max-load}. @emph{max-load} uses
the same syntax as @strong{--jobs}, so @emph{100%} for one per CPU is a valid
setting. Only difference is 0 which is interpreted as 0.01.

@item @strong{--controlmaster}
@anchor{@strong{--controlmaster}}

@item @strong{-M}
@anchor{@strong{-M}}

Use ssh's ControlMaster to make ssh connections faster. Useful if jobs
run remote and are very fast to run. This is disabled for sshlogins
that specify their own ssh command.

@item @strong{--xargs}
@anchor{@strong{--xargs}}

Multiple arguments. Insert as many arguments as the command line
length permits.

If @strong{@{@}} is not used the arguments will be appended to the
line.  If @strong{@{@}} is used multiple times each @strong{@{@}} will be replaced
with all the arguments.

Support for @strong{--xargs} with @strong{--sshlogin} is limited and may fail.

See also @strong{-X} for context replace. If in doubt use @strong{-X} as that will
most likely do what is needed.

@item @strong{-m}
@anchor{@strong{-m}}

Multiple arguments. Insert as many arguments as the command line
length permits. If multiple jobs are being run in parallel: distribute
the arguments evenly among the jobs. Use @strong{-j1} or @strong{--xargs} to avoid this.

If @strong{@{@}} is not used the arguments will be appended to the
line.  If @strong{@{@}} is used multiple times each @strong{@{@}} will be replaced
with all the arguments.

Support for @strong{-m} with @strong{--sshlogin} is limited and may fail.

See also @strong{-X} for context replace. If in doubt use @strong{-X} as that will
most likely do what is needed.

@item @strong{--memfree} @emph{size}
@anchor{@strong{--memfree} @emph{size}}

Minimum memory free when starting another job. The @emph{size} can be
postfixed with K, M, G, T, P, k, m, g, t, or p which would multiply
the size with 1024, 1048576, 1073741824, 1099511627776,
1125899906842624, 1000, 1000000, 1000000000, 1000000000000, or
1000000000000000, respectively.

If the jobs take up very different amount of RAM, GNU @strong{parallel} will
only start as many as there is memory for. If less than @emph{size} bytes
are free, no more jobs will be started. If less than 50% @emph{size} bytes
are free, the youngest job will be killed, and put back on the queue
to be run later.

@strong{--retries} must be set to determine how many times GNU @strong{parallel}
should retry a given job.

@item @strong{--minversion} @emph{version}
@anchor{@strong{--minversion} @emph{version}}

Print the version GNU @strong{parallel} and exit.  If the current version of
GNU @strong{parallel} is less than @emph{version} the exit code is
255. Otherwise it is 0.

This is useful for scripts that depend on features only available from
a certain version of GNU @strong{parallel}.

@item @strong{--nonall}
@anchor{@strong{--nonall}}

@strong{--onall} with no arguments. Run the command on all computers given
with @strong{--sshlogin} but take no arguments. GNU @strong{parallel} will log
into @strong{--jobs} number of computers in parallel and run the job on the
computer. @strong{-j} adjusts how many computers to log into in parallel.

This is useful for running the same command (e.g. uptime) on a list of
servers.

@item @strong{--onall}
@anchor{@strong{--onall}}

Run all the jobs on all computers given with @strong{--sshlogin}. GNU
@strong{parallel} will log into @strong{--jobs} number of computers in parallel
and run one job at a time on the computer. The order of the jobs will
not be changed, but some computers may finish before others.

When using @strong{--group} the output will be grouped by each server, so
all the output from one server will be grouped together.

@strong{--joblog} will contain an entry for each job on each server, so
there will be several job sequence 1.

@item @strong{--output-as-files}
@anchor{@strong{--output-as-files}}

@item @strong{--outputasfiles}
@anchor{@strong{--outputasfiles}}

@item @strong{--files}
@anchor{@strong{--files}}

Instead of printing the output to stdout (standard output) the output
of each job is saved in a file and the filename is then printed.

See also: @strong{--results}

@item @strong{--pipe}
@anchor{@strong{--pipe}}

@item @strong{--spreadstdin}
@anchor{@strong{--spreadstdin}}

Spread input to jobs on stdin (standard input). Read a block of data
from stdin (standard input) and give one block of data as input to one
job.

The block size is determined by @strong{--block}. The strings @strong{--recstart}
and @strong{--recend} tell GNU @strong{parallel} how a record starts and/or
ends. The block read will have the final partial record removed before
the block is passed on to the job. The partial record will be
prepended to next block.

If @strong{--recstart} is given this will be used to split at record start.

If @strong{--recend} is given this will be used to split at record end.

If both @strong{--recstart} and @strong{--recend} are given both will have to
match to find a split position.

If neither @strong{--recstart} nor @strong{--recend} are given @strong{--recend}
defaults to '\n'. To have no record separator use @strong{--recend ""}.

@strong{--files} is often used with @strong{--pipe}.

@strong{--pipe} maxes out at around 1 GB/s input, and 100 MB/s output. If
performance is important use @strong{--pipepart}.

See also: @strong{--recstart}, @strong{--recend}, @strong{--fifo}, @strong{--cat},
@strong{--pipepart}, @strong{--files}.

@item @strong{--pipepart}
@anchor{@strong{--pipepart}}

Pipe parts of a physical file. @strong{--pipepart} works similar to
@strong{--pipe}, but is much faster.

@strong{--pipepart} has a few limitations:

@itemize
@item The file must be a normal file or a block device (technically it must
be seekable) and must be given using @strong{-a} or @strong{::::}. The file cannot
be a pipe or a fifo as they are not seekable.

If using a block device with lot of NUL bytes, remember to set
@strong{--recend ''}.

@item Record counting (@strong{-N}) and line counting (@strong{-L}/@strong{-l}) do not work.

@end itemize

@item @strong{--plain}
@anchor{@strong{--plain}}

Ignore any @strong{--profile}, $PARALLEL, and ~/.parallel/config to get full
control on the command line (used by GNU @strong{parallel} internally when
called with @strong{--sshlogin}).

@item @strong{--plus}
@anchor{@strong{--plus}}

Activate additional replacement strings: @{+/@} @{+.@} @{+..@} @{+...@} @{..@}
@{...@} @{/..@} @{/...@} @{##@}. The idea being that '@{+foo@}' matches the opposite of
'@{foo@}' and @{@} = @{+/@}/@{/@} = @{.@}.@{+.@} = @{+/@}/@{/.@}.@{+.@} = @{..@}.@{+..@} =
@{+/@}/@{/..@}.@{+..@} = @{...@}.@{+...@} = @{+/@}/@{/...@}.@{+...@}

@strong{@{##@}} is the number of jobs to be run. It is incompatible with
@strong{-X}/@strong{-m}/@strong{--xargs}.

@strong{@{choose_k@}} is inspired by n choose k: Given a list of n elements,
choose k. k is the number of input sources and n is the number of
arguments in an input source.  The content of the input sources must
be the same and the arguments must be unique.

The following dynamic replacement strings are also activated. They are
inspired by bash's parameter expansion:

@verbatim
  {:-str}       str if the value is empty
  {:num}        remove the first num characters
  {:num1:num2}  characters from num1 to num2
  {#str}        remove prefix str
  {%str}        remove postfix str
  {/str1/str2}  replace str1 with str2
  {^str}        uppercase str if found at the start
  {^^str}       uppercase str
  {,str}        lowercase str if found at the start
  {,,str}       lowercase str
@end verbatim

@item @strong{--progress}
@anchor{@strong{--progress}}

Show progress of computations. List the computers involved in the task
with number of CPUs detected and the max number of jobs to run. After
that show progress for each computer: number of running jobs, number
of completed jobs, and percentage of all jobs done by this
computer. The percentage will only be available after all jobs have
been scheduled as GNU @strong{parallel} only read the next job when ready to
schedule it - this is to avoid wasting time and memory by reading
everything at startup.

By sending GNU @strong{parallel} SIGUSR2 you can toggle turning on/off
@strong{--progress} on a running GNU @strong{parallel} process.

See also @strong{--eta} and @strong{--bar}.

@item @strong{--max-args}=@emph{max-args}
@anchor{@strong{--max-args}=@emph{max-args}}

@item @strong{-n} @emph{max-args}
@anchor{@strong{-n} @emph{max-args}}

Use at most @emph{max-args} arguments per command line.  Fewer than
@emph{max-args} arguments will be used if the size (see the @strong{-s} option)
is exceeded, unless the @strong{-x} option is given, in which case
GNU @strong{parallel} will exit.

@strong{-n 0} means read one argument, but insert 0 arguments on the command
line.

Implies @strong{-X} unless @strong{-m} is set.

@item @strong{--max-replace-args}=@emph{max-args}
@anchor{@strong{--max-replace-args}=@emph{max-args}}

@item @strong{-N} @emph{max-args}
@anchor{@strong{-N} @emph{max-args}}

Use at most @emph{max-args} arguments per command line. Like @strong{-n} but
also makes replacement strings @strong{@{1@}} .. @strong{@{}@emph{max-args}@strong{@}} that
represents argument 1 .. @emph{max-args}. If too few args the @strong{@{}@emph{n}@strong{@}} will
be empty.

@strong{-N 0} means read one argument, but insert 0 arguments on the command
line.

This will set the owner of the homedir to the user:

@verbatim
  tr ':' '\n' < /etc/passwd | parallel -N7 chown {1} {6}
@end verbatim

Implies @strong{-X} unless @strong{-m} or @strong{--pipe} is set.

When used with @strong{--pipe} @strong{-N} is the number of records to read. This
is somewhat slower than @strong{--block}.

@item @strong{--max-line-length-allowed}
@anchor{@strong{--max-line-length-allowed}}

Print the maximal number of characters allowed on the command line and
exit (used by GNU @strong{parallel} itself to determine the line length
on remote computers).

@item @strong{--number-of-cpus} (obsolete)
@anchor{@strong{--number-of-cpus} (obsolete)}

Print the number of physical CPU cores and exit.

@item @strong{--number-of-cores}
@anchor{@strong{--number-of-cores}}

Print the number of physical CPU cores and exit (used by GNU @strong{parallel} itself
to determine the number of physical CPU cores on remote computers).

@item @strong{--number-of-sockets}
@anchor{@strong{--number-of-sockets}}

Print the number of filled CPU sockets and exit (used by GNU
@strong{parallel} itself to determine the number of filled CPU sockets on
remote computers).

@item @strong{--number-of-threads}
@anchor{@strong{--number-of-threads}}

Print the number of hyperthreaded CPU cores and exit (used by GNU
@strong{parallel} itself to determine the number of hyperthreaded CPU cores
on remote computers).

@item @strong{--no-keep-order}
@anchor{@strong{--no-keep-order}}

Overrides an earlier @strong{--keep-order} (e.g. if set in
@strong{~/.parallel/config}).

@item @strong{--nice} @emph{niceness}
@anchor{@strong{--nice} @emph{niceness}}

Run the command at this niceness. For simple commands you can just add
@strong{nice} in front of the command. But if the command consists of more
sub commands (Like: ls|wc) then prepending @strong{nice} will not always
work. @strong{--nice} will make sure all sub commands are niced - even on
remote servers.

@item @strong{--interactive}
@anchor{@strong{--interactive}}

@item @strong{-p}
@anchor{@strong{-p}}

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 @strong{-t}.

@item @strong{--parens} @emph{parensstring}
@anchor{@strong{--parens} @emph{parensstring}}

Define start and end parenthesis for @strong{@{= perl expression =@}}. The
left and the right parenthesis can be multiple characters and are
assumed to be the same length. The default is @strong{@{==@}} giving @strong{@{=} as
the start parenthesis and @strong{=@}} as the end parenthesis.

Another useful setting is @strong{,,,,} which would make both parenthesis
@strong{,,}:

@verbatim
  parallel --parens ,,,, echo foo is ,,s/I/O/g,, ::: FII
@end verbatim

See also: @strong{--rpl} @strong{@{= perl expression =@}}

@item @strong{--profile} @emph{profilename}
@anchor{@strong{--profile} @emph{profilename}}

@item @strong{-J} @emph{profilename}
@anchor{@strong{-J} @emph{profilename}}

Use profile @emph{profilename} for options. This is useful if you want to
have multiple profiles. You could have one profile for running jobs in
parallel on the local computer and a different profile for running jobs
on remote computers. See the section PROFILE FILES for examples.

@emph{profilename} corresponds to the file ~/.parallel/@emph{profilename}.

You can give multiple profiles by repeating @strong{--profile}. If parts of
the profiles conflict, the later ones will be used.

Default: config

@item @strong{--quote}
@anchor{@strong{--quote}}

@item @strong{-q}
@anchor{@strong{-q}}

Quote @emph{command}. The command must be a simple command (see @strong{man
bash}) without redirections and without variable assignments. This
will quote the command line and arguments so special characters are
not interpreted by the shell. See the section QUOTING. Most people
will never need this.  Quoting is disabled by default.

@item @strong{--no-run-if-empty}
@anchor{@strong{--no-run-if-empty}}

@item @strong{-r}
@anchor{@strong{-r}}

If the stdin (standard input) only contains whitespace, do not run the command.

If used with @strong{--pipe} this is slow.

@item @strong{--noswap}
@anchor{@strong{--noswap}}

Do not start new jobs on a given computer if there is both swap-in and
swap-out activity.

The swap activity is only sampled every 10 seconds as the sampling
takes 1 second to do.

Swap activity is computed as (swap-in)*(swap-out) which in practice is
a good value: swapping out is not a problem, swapping in is not a
problem, but both swapping in and out usually indicates a problem.

@strong{--memfree} may give better results, so try using that first.

@item @strong{--record-env}
@anchor{@strong{--record-env}}

Record current environment variables in ~/.parallel/ignored_vars. This
is useful before using @strong{--env _}.

See also @strong{--env}, @strong{--session}.

@item @strong{--recstart} @emph{startstring}
@anchor{@strong{--recstart} @emph{startstring}}

@item @strong{--recend} @emph{endstring}
@anchor{@strong{--recend} @emph{endstring}}

If @strong{--recstart} is given @emph{startstring} will be used to split at record start.

If @strong{--recend} is given @emph{endstring} will be used to split at record end.

If both @strong{--recstart} and @strong{--recend} are given the combined string
@emph{endstring}@emph{startstring} will have to match to find a split
position. This is useful if either @emph{startstring} or @emph{endstring}
match in the middle of a record.

If neither @strong{--recstart} nor @strong{--recend} are given then @strong{--recend}
defaults to '\n'. To have no record separator use @strong{--recend ""}.

@strong{--recstart} and @strong{--recend} are used with @strong{--pipe}.

Use @strong{--regexp} to interpret @strong{--recstart} and @strong{--recend} as regular
expressions. This is slow, however.

@item @strong{--regexp}
@anchor{@strong{--regexp}}

Use @strong{--regexp} to interpret @strong{--recstart} and @strong{--recend} as regular
expressions. This is slow, however.

@item @strong{--remove-rec-sep}
@anchor{@strong{--remove-rec-sep}}

@item @strong{--removerecsep}
@anchor{@strong{--removerecsep}}

@item @strong{--rrs}
@anchor{@strong{--rrs}}

Remove the text matched by @strong{--recstart} and @strong{--recend} before piping
it to the command.

Only used with @strong{--pipe}.

@item @strong{--results} @emph{name}
@anchor{@strong{--results} @emph{name}}

@item @strong{--res} @emph{name}
@anchor{@strong{--res} @emph{name}}

Save the output into files.

@strong{Simple string output dir}

If @emph{name} does not contain replacement strings and does not end in
@strong{.csv/.tsv}, the output will be stored in a directory tree rooted at
@emph{name}.  Within this directory tree, each command will result in
three files: @emph{name}/<ARGS>/stdout and @emph{name}/<ARGS>/stderr,
@emph{name}/<ARGS>/seq, where <ARGS> is a sequence of directories
representing the header of the input source (if using @strong{--header :})
or the number of the input source and corresponding values.

E.g:

@verbatim
  parallel --header : --results foo echo {a} {b} \
    ::: a I II ::: b III IIII
@end verbatim

will generate the files:

@verbatim
  foo/a/II/b/III/seq
  foo/a/II/b/III/stderr
  foo/a/II/b/III/stdout
  foo/a/II/b/IIII/seq
  foo/a/II/b/IIII/stderr
  foo/a/II/b/IIII/stdout
  foo/a/I/b/III/seq
  foo/a/I/b/III/stderr
  foo/a/I/b/III/stdout
  foo/a/I/b/IIII/seq
  foo/a/I/b/IIII/stderr
  foo/a/I/b/IIII/stdout
@end verbatim

and

@verbatim
  parallel --results foo echo {1} {2} ::: I II ::: III IIII
@end verbatim

will generate the files:

@verbatim
  foo/1/II/2/III/seq
  foo/1/II/2/III/stderr
  foo/1/II/2/III/stdout
  foo/1/II/2/IIII/seq
  foo/1/II/2/IIII/stderr
  foo/1/II/2/IIII/stdout
  foo/1/I/2/III/seq
  foo/1/I/2/III/stderr
  foo/1/I/2/III/stdout
  foo/1/I/2/IIII/seq
  foo/1/I/2/IIII/stderr
  foo/1/I/2/IIII/stdout
@end verbatim

@strong{CSV file output}

If @emph{name} ends in @strong{.csv}/@strong{.tsv} the output will be a CSV-file
named @emph{name}.

@strong{.csv} gives a comma separated value file. @strong{.tsv} gives a TAB
separated value file.

@strong{-.csv}/@strong{-.tsv} are special: It will give the file on stdout
(standard output).

@strong{Replacement string output file}

If @emph{name} contains a replacement string and the replaced result does
not end in /, then the standard output will be stored in a file named
by this result. Standard error will be stored in the same file name
with '.err' added, and the sequence number will be stored in the same
file name with '.seq' added.

E.g.

@verbatim
  parallel --results my_{} echo ::: foo bar baz
@end verbatim

will generate the files:

@verbatim
  my_bar
  my_bar.err
  my_bar.seq
  my_baz
  my_baz.err
  my_baz.seq
  my_foo
  my_foo.err
  my_foo.seq
@end verbatim

@strong{Replacement string output dir}

If @emph{name} contains a replacement string and the replaced result ends
in /, then output files will be stored in the resulting dir.

E.g.

@verbatim
  parallel --results my_{}/ echo ::: foo bar baz
@end verbatim

will generate the files:

@verbatim
  my_bar/seq
  my_bar/stderr
  my_bar/stdout
  my_baz/seq
  my_baz/stderr
  my_baz/stdout
  my_foo/seq
  my_foo/stderr
  my_foo/stdout
@end verbatim

See also @strong{--files}, @strong{--tag}, @strong{--header}, @strong{--joblog}.

@item @strong{--resume}
@anchor{@strong{--resume}}

Resumes from the last unfinished job. By reading @strong{--joblog} or the
@strong{--results} dir GNU @strong{parallel} will figure out the last unfinished
job and continue from there. As GNU @strong{parallel} only looks at the
sequence numbers in @strong{--joblog} then the input, the command, and
@strong{--joblog} all have to remain unchanged; otherwise GNU @strong{parallel}
may run wrong commands.

See also @strong{--joblog}, @strong{--results}, @strong{--resume-failed}, @strong{--retries}.

@item @strong{--resume-failed}
@anchor{@strong{--resume-failed}}

Retry all failed and resume from the last unfinished job. By reading
@strong{--joblog} GNU @strong{parallel} will figure out the failed jobs and run
those again. After that it will resume last unfinished job and
continue from there. As GNU @strong{parallel} only looks at the sequence
numbers in @strong{--joblog} then the input, the command, and @strong{--joblog}
all have to remain unchanged; otherwise GNU @strong{parallel} may run wrong
commands.

See also @strong{--joblog}, @strong{--resume}, @strong{--retry-failed}, @strong{--retries}.

@item @strong{--retry-failed}
@anchor{@strong{--retry-failed}}

Retry all failed jobs in joblog. By reading @strong{--joblog} GNU
@strong{parallel} will figure out the failed jobs and run those again.

@strong{--retry-failed} ignores the command and arguments on the command
line: It only looks at the joblog.

@strong{Differences between --resume, --resume-failed, --retry-failed}

In this example @strong{exit @{= $_%=2 =@}} will cause every other job to fail.

@verbatim
  timeout -k 1 4 parallel --joblog log -j10 \
    'sleep {}; exit {= $_%=2 =}' ::: {10..1}
@end verbatim

4 jobs completed. 2 failed:

@verbatim
  Seq   [...]   Exitval Signal  Command
  10    [...]   1       0       sleep 1; exit 1
  9     [...]   0       0       sleep 2; exit 0
  8     [...]   1       0       sleep 3; exit 1
  7     [...]   0       0       sleep 4; exit 0
@end verbatim

@strong{--resume} does not care about the Exitval, but only looks at Seq. If
the Seq is run, it will not be run again. So if needed, you can change
the command for the seqs not run yet:

@verbatim
  parallel --resume --joblog log -j10 \
    'sleep .{}; exit {= $_%=2 =}' ::: {10..1}

  Seq   [...]   Exitval Signal  Command
  [... as above ...]
  1     [...]   0       0       sleep .10; exit 0
  6     [...]   1       0       sleep .5; exit 1
  5     [...]   0       0       sleep .6; exit 0
  4     [...]   1       0       sleep .7; exit 1
  3     [...]   0       0       sleep .8; exit 0
  2     [...]   1       0       sleep .9; exit 1
@end verbatim

@strong{--resume-failed} cares about the Exitval, but also only looks at Seq
to figure out which commands to run. Again this means you can change
the command, but not the arguments. It will run the failed seqs and
the seqs not yet run:

@verbatim
  parallel --resume-failed --joblog log -j10 \
    'echo {};sleep .{}; exit {= $_%=3 =}' ::: {10..1}

  Seq   [...]   Exitval Signal  Command
  [... as above ...]
  10    [...]   1       0       echo 1;sleep .1; exit 1
  8     [...]   0       0       echo 3;sleep .3; exit 0
  6     [...]   2       0       echo 5;sleep .5; exit 2
  4     [...]   1       0       echo 7;sleep .7; exit 1
  2     [...]   0       0       echo 9;sleep .9; exit 0
@end verbatim

@strong{--retry-failed} cares about the Exitval, but takes the command from
the joblog. It ignores any arguments or commands given on the command
line:

@verbatim
  parallel --retry-failed --joblog log -j10 this part is ignored

  Seq   [...]   Exitval Signal  Command
  [... as above ...]
  10    [...]   1       0       echo 1;sleep .1; exit 1
  6     [...]   2       0       echo 5;sleep .5; exit 2
  4     [...]   1       0       echo 7;sleep .7; exit 1
@end verbatim

See also @strong{--joblog}, @strong{--resume}, @strong{--resume-failed}, @strong{--retries}.

@item @strong{--retries} @emph{n}
@anchor{@strong{--retries} @emph{n}}

If a job fails, retry it on another computer on which it has not
failed. Do this @emph{n} times. If there are fewer than @emph{n} computers in
@strong{--sshlogin} GNU @strong{parallel} will re-use all the computers. This is
useful if some jobs fail for no apparent reason (such as network
failure).

@item @strong{--return} @emph{filename}
@anchor{@strong{--return} @emph{filename}}

Transfer files from remote computers. @strong{--return} is used with
@strong{--sshlogin} when the arguments are files on the remote computers. When
processing is done the file @emph{filename} will be transferred
from the remote computer using @strong{rsync} and will be put relative to
the default login dir. E.g.

@verbatim
  echo foo/bar.txt | parallel --return {.}.out \
    --sshlogin server.example.com touch {.}.out
@end verbatim

This will transfer the file @emph{$HOME/foo/bar.out} from the computer
@emph{server.example.com} to the file @emph{foo/bar.out} after running
@strong{touch foo/bar.out} on @emph{server.example.com}.

@verbatim
  parallel -S server --trc out/./{}.out touch {}.out ::: in/file
@end verbatim

This will transfer the file @emph{in/file.out} from the computer
@emph{server.example.com} to the files @emph{out/in/file.out} after running
@strong{touch in/file.out} on @emph{server}.

@verbatim
  echo /tmp/foo/bar.txt | parallel --return {.}.out \
    --sshlogin server.example.com touch {.}.out
@end verbatim

This will transfer the file @emph{/tmp/foo/bar.out} from the computer
@emph{server.example.com} to the file @emph{/tmp/foo/bar.out} after running
@strong{touch /tmp/foo/bar.out} on @emph{server.example.com}.

Multiple files can be transferred by repeating the option multiple
times:

@verbatim
  echo /tmp/foo/bar.txt | parallel \
    --sshlogin server.example.com \
    --return {.}.out --return {.}.out2 touch {.}.out {.}.out2
@end verbatim

@strong{--return} is often used with @strong{--transferfile} and @strong{--cleanup}.

@strong{--return} is ignored when used with @strong{--sshlogin :} or when not used
with @strong{--sshlogin}.

@item @strong{--round-robin}
@anchor{@strong{--round-robin}}

@item @strong{--round}
@anchor{@strong{--round}}

Normally @strong{--pipe} will give a single block to each instance of the
command. With @strong{--roundrobin} all blocks will at random be written to
commands already running. This is useful if the command takes a long
time to initialize.

@strong{--keep-order} will not work with @strong{--roundrobin} as it is
impossible to track which input block corresponds to which output.

@strong{--roundrobin} implies @strong{--pipe}, except if @strong{--pipepart} is given.

@item @strong{--rpl} '@emph{tag} @emph{perl expression}'
@anchor{@strong{--rpl} '@emph{tag} @emph{perl expression}'}

Use @emph{tag} as a replacement string for @emph{perl expression}. This makes
it possible to define your own replacement strings. GNU @strong{parallel}'s
7 replacement strings are implemented as:

@verbatim
  --rpl '{} '
  --rpl '{#} 1 $_=$job->seq()'
  --rpl '{%} 1 $_=$job->slot()'
  --rpl '{/} s:.*/::'
  --rpl '{//} $Global::use{"File::Basename"} ||=
    eval "use File::Basename; 1;"; $_ = dirname($_);'
  --rpl '{/.} s:.*/::; s:\.[^/.]+$::;'
  --rpl '{.} s:\.[^/.]+$::'
@end verbatim

The @strong{--plus} replacement strings are implemented as:

@verbatim
  --rpl '{+/} s:/[^/]*$::'
  --rpl '{+.} s:.*\.::'
  --rpl '{+..} s:.*\.([^.]*\.):$1:'
  --rpl '{+...} s:.*\.([^.]*\.[^.]*\.):$1:'
  --rpl '{..} s:\.[^/.]+$::; s:\.[^/.]+$::'
  --rpl '{...} s:\.[^/.]+$::; s:\.[^/.]+$::; s:\.[^/.]+$::'
  --rpl '{/..} s:.*/::; s:\.[^/.]+$::; s:\.[^/.]+$::'
  --rpl '{/...} s:.*/::;s:\.[^/.]+$::;s:\.[^/.]+$::;s:\.[^/.]+$::'
  --rpl '{##} $_=total_jobs()'
  --rpl '{:-(.+?)} $_ ||= $$1'
  --rpl '{:(\d+?)} substr($_,0,$$1) = ""'
  --rpl '{:(\d+?):(\d+?)} $_ = substr($_,$$1,$$2);'
  --rpl '{#([^#].*?)} s/^$$1//;'
  --rpl '{%(.+?)} s/$$1$//;'
  --rpl '{/(.+?)/(.*?)} s/$$1/$$2/;'
  --rpl '{^(.+?)} s/^($$1)/uc($1)/e;'
  --rpl '{^^(.+?)} s/($$1)/uc($1)/eg;'
  --rpl '{,(.+?)} s/^($$1)/lc($1)/e;'
  --rpl '{,,(.+?)} s/($$1)/lc($1)/eg;'
@end verbatim

If the user defined replacement string starts with '@{' it can also be
used as a positional replacement string (like @strong{@{2.@}}).

It is recommended to only change $_ but you have full access to all
of GNU @strong{parallel}'s internal functions and data structures.

Here are a few examples:

@verbatim
  Is the job sequence even or odd?
  --rpl '{odd} $_ = seq() % 2 ? "odd" : "even"'
  Pad job sequence with leading zeros to get equal width
  --rpl '{0#} $f=1+int("".(log(total_jobs())/log(10)));
    $_=sprintf("%0${f}d",seq())'
  Job sequence counting from 0
  --rpl '{#0} $_ = seq() - 1'
  Job slot counting from 2
  --rpl '{%1} $_ = slot() + 1'
  Remove all extensions
  --rpl '{:} s:(\.[^/]+)*$::'
@end verbatim

You can have dynamic replacement strings by including parenthesis in
the replacement string and adding a regular expression between the
parenthesis. The matching string will be inserted as $$1:

@verbatim
  parallel --rpl '{%(.*?)} s/$$1//' echo {%.tar.gz} ::: my.tar.gz
  parallel --rpl '{:%(.+?)} s:$$1(\.[^/]+)*$::' \
    echo {:%_file} ::: my_file.tar.gz
  parallel -n3 --rpl '{/:%(.*?)} s:.*/(.*)$$1(\.[^/]+)*$:$1:' \
    echo job {#}: {2} {2.} {3/:%_1} ::: a/b.c c/d.e f/g_1.h.i
@end verbatim

You can even use multiple matches:

@verbatim
  parallel --rpl '{/(.+?)/(.*?)} s/$$1/$$2/;'
    echo {/replacethis/withthis} {/b/C} ::: a_replacethis_b

  parallel --rpl '{(.*?)/(.*?)} $_="$$2$_$$1"' \
    echo {swap/these} ::: -middle-
@end verbatim

See also: @strong{@{= perl expression =@}} @strong{--parens}

@item @strong{--rsync-opts} @emph{options}
@anchor{@strong{--rsync-opts} @emph{options}}

Options to pass on to @strong{rsync}. Setting @strong{--rsync-opts} takes
precedence over setting the environment variable $PARALLEL_RSYNC_OPTS.

@item @strong{--max-chars}=@emph{max-chars}
@anchor{@strong{--max-chars}=@emph{max-chars}}

@item @strong{-s} @emph{max-chars}
@anchor{@strong{-s} @emph{max-chars}}

Use at most @emph{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.

Implies @strong{-X} unless @strong{-m} is set.

@item @strong{--show-limits}
@anchor{@strong{--show-limits}}

Display the limits on the command-line length which are imposed by the
operating system and the @strong{-s} option.  Pipe the input from /dev/null
(and perhaps specify --no-run-if-empty) if you don't want GNU @strong{parallel}
to do anything.

@item @strong{--semaphore}
@anchor{@strong{--semaphore}}

Work as a counting semaphore. @strong{--semaphore} will cause GNU
@strong{parallel} to start @emph{command} in the background. When the number of
jobs given by @strong{--jobs} is reached, GNU @strong{parallel} will wait for one of
these to complete before starting another command.

@strong{--semaphore} implies @strong{--bg} unless @strong{--fg} is specified.

@strong{--semaphore} implies @strong{--semaphorename `tty`} unless
@strong{--semaphorename} is specified.

Used with @strong{--fg}, @strong{--wait}, and @strong{--semaphorename}.

The command @strong{sem} is an alias for @strong{parallel --semaphore}.

See also @strong{man sem}.

@item @strong{--semaphorename} @emph{name}
@anchor{@strong{--semaphorename} @emph{name}}

@item @strong{--id} @emph{name}
@anchor{@strong{--id} @emph{name}}

Use @strong{name} as the name of the semaphore. Default is the name of the
controlling tty (output from @strong{tty}).

The default normally works as expected when used interactively, but
when used in a script @emph{name} should be set. @emph{$$} or @emph{my_task_name}
are often a good value.

The semaphore is stored in ~/.parallel/semaphores/

Implies @strong{--semaphore}.

See also @strong{man sem}.

@item @strong{--semaphoretimeout} @emph{secs}
@anchor{@strong{--semaphoretimeout} @emph{secs}}

@item @strong{--st} @emph{secs}
@anchor{@strong{--st} @emph{secs}}

If @emph{secs} > 0: If the semaphore is not released within @emph{secs} seconds, take it anyway.

If @emph{secs} < 0: If the semaphore is not released within @emph{secs} seconds, exit.

Implies @strong{--semaphore}.

See also @strong{man sem}.

@item @strong{--seqreplace} @emph{replace-str}
@anchor{@strong{--seqreplace} @emph{replace-str}}

Use the replacement string @emph{replace-str} instead of @strong{@{#@}} for
job sequence number.

@item @strong{--session}
@anchor{@strong{--session}}

Record names in current environment in @strong{$PARALLEL_IGNORED_NAMES} and
exit. Only used with @strong{env_parallel}. Aliases, functions, and
variables with names in @strong{$PARALLEL_IGNORED_NAMES} will not be copied.

Only supported in @strong{Ash, Bash, Dash, Ksh, Sh, and Zsh}.

See also @strong{--env}, @strong{--record-env}.

@item @strong{--shard} @emph{shardkey} (beta testing)
@anchor{@strong{--shard} @emph{shardkey} (beta testing)}

Use column @emph{shardkey} as shard key and shard input to the jobs.

Each input line is split using @strong{--colsep}. The value in the
@emph{shardkey} column is hashed so that all lines of a given value is
given to the same job slot.

This is similar to sharding in databases.

The performance is in the order of 100K rows per second. Faster if the
@emph{shardkey} is small (<10), slower if it is big (>100).

@strong{--shard} requires @strong{--pipe} and a fixed numeric value for @strong{--jobs}.

@item @strong{--shebang}
@anchor{@strong{--shebang}}

@item @strong{--hashbang}
@anchor{@strong{--hashbang}}

GNU @strong{parallel} can be called as a shebang (#!) command as the first
line of a script. The content of the file will be treated as
inputsource.

Like this:

@verbatim
  #!/usr/bin/parallel --shebang -r wget

  https://ftpmirror.gnu.org/parallel/parallel-20120822.tar.bz2
  https://ftpmirror.gnu.org/parallel/parallel-20130822.tar.bz2
  https://ftpmirror.gnu.org/parallel/parallel-20140822.tar.bz2
@end verbatim

@strong{--shebang} must be set as the first option.

On FreeBSD @strong{env} is needed:

@verbatim
  #!/usr/bin/env -S parallel --shebang -r wget

  https://ftpmirror.gnu.org/parallel/parallel-20120822.tar.bz2
  https://ftpmirror.gnu.org/parallel/parallel-20130822.tar.bz2
  https://ftpmirror.gnu.org/parallel/parallel-20140822.tar.bz2
@end verbatim

There are many limitations of shebang (#!) depending on your operating
system. See details on http://www.in-ulm.de/~mascheck/various/shebang/

@item @strong{--shebang-wrap}
@anchor{@strong{--shebang-wrap}}

GNU @strong{parallel} can parallelize scripts by wrapping the shebang
line. If the program can be run like this:

@verbatim
  cat arguments | parallel the_program
@end verbatim

then the script can be changed to:

@verbatim
  #!/usr/bin/parallel --shebang-wrap /original/parser --options
@end verbatim

E.g.

@verbatim
  #!/usr/bin/parallel --shebang-wrap /usr/bin/python
@end verbatim

If the program can be run like this:

@verbatim
  cat data | parallel --pipe the_program
@end verbatim

then the script can be changed to:

@verbatim
  #!/usr/bin/parallel --shebang-wrap --pipe /orig/parser --opts
@end verbatim

E.g.

@verbatim
  #!/usr/bin/parallel --shebang-wrap --pipe /usr/bin/perl -w
@end verbatim

@strong{--shebang-wrap} must be set as the first option.

@item @strong{--shellquote}
@anchor{@strong{--shellquote}}

Does not run the command but quotes it. Useful for making quoted
composed commands for GNU @strong{parallel}.

Multiple @strong{--shellquote} with quote the string multiple times, so
@strong{parallel --shellquote | parallel --shellquote} can be written as
@strong{parallel --shellquote --shellquote}.

@item @strong{--shuf}
@anchor{@strong{--shuf}}

Shuffle jobs. When having multiple input sources it is hard to
randomize jobs. --shuf will generate all jobs, and shuffle them before
running them. This is useful to get a quick preview of the results
before running the full batch.

@item @strong{--skip-first-line}
@anchor{@strong{--skip-first-line}}

Do not use the first line of input (used by GNU @strong{parallel} itself
when called with @strong{--shebang}).

@item @strong{--sql} @emph{DBURL} (obsolete)
@anchor{@strong{--sql} @emph{DBURL} (obsolete)}

Use @strong{--sqlmaster} instead.

@item @strong{--sqlmaster} @emph{DBURL}
@anchor{@strong{--sqlmaster} @emph{DBURL}}

Submit jobs via SQL server. @emph{DBURL} must point to a table, which will
contain the same information as @strong{--joblog}, the values from the input
sources (stored in columns V1 .. Vn), and the output (stored in
columns Stdout and Stderr).

If @emph{DBURL} is prepended with '+' GNU @strong{parallel} assumes the table is
already made with the correct columns and appends the jobs to it.

If @emph{DBURL} is not prepended with '+' the table will be dropped and
created with the correct amount of V-columns unless

@strong{--sqlmaster} does not run any jobs, but it creates the values for
the jobs to be run. One or more @strong{--sqlworker} must be run to actually
execute the jobs.

If @strong{--wait} is set, GNU @strong{parallel} will wait for the jobs to
complete.

The format of a DBURL is:

@verbatim
  [sql:]vendor://[[user][:pwd]@][host][:port]/[db]/table
@end verbatim

E.g.

@verbatim
  sql:mysql://hr:hr@localhost:3306/hrdb/jobs
  mysql://scott:tiger@my.example.com/pardb/paralleljobs
  sql:oracle://scott:tiger@ora.example.com/xe/parjob
  postgresql://scott:tiger@pg.example.com/pgdb/parjob
  pg:///parjob
  sqlite3:///pardb/parjob
@end verbatim

It can also be an alias from ~/.sql/aliases:

@verbatim
  :myalias mysql:///mydb/paralleljobs
@end verbatim

@item @strong{--sqlandworker} @emph{DBURL}
@anchor{@strong{--sqlandworker} @emph{DBURL}}

Shorthand for: @strong{--sqlmaster} @emph{DBURL} @strong{--sqlworker} @emph{DBURL}.

@item @strong{--sqlworker} @emph{DBURL}
@anchor{@strong{--sqlworker} @emph{DBURL}}

Execute jobs via SQL server. Read the input sources variables from the
table pointed to by @emph{DBURL}. The @emph{command} on the command line
should be the same as given by @strong{--sqlmaster}.

If you have more than one @strong{--sqlworker} jobs may be run more than
once.

If @strong{--sqlworker} runs on the local machine, the hostname in the SQL
table will not be ':' but instead the hostname of the machine.

@item @strong{--ssh} @emph{sshcommand}
@anchor{@strong{--ssh} @emph{sshcommand}}

GNU @strong{parallel} defaults to using @strong{ssh} for remote access. This can
be overridden with @strong{--ssh}. It can also be set on a per server
basis (see @strong{--sshlogin}).

@item @strong{--sshdelay} @emph{secs}
@anchor{@strong{--sshdelay} @emph{secs}}

Delay starting next ssh by @emph{secs} seconds. GNU @strong{parallel} will pause
@emph{secs} seconds after starting each ssh. @emph{secs} can be less than 1
seconds.

@item @strong{-S} @emph{[@@hostgroups/][ncpus/]sshlogin[,[@@hostgroups/][ncpus/]sshlogin[,...]]}
@anchor{@strong{-S} @emph{[@@hostgroups/][ncpus/]sshlogin[@comma{}[@@hostgroups/][ncpus/]sshlogin[@comma{}...]]}}

@item @strong{-S} @emph{@@hostgroup}
@anchor{@strong{-S} @emph{@@hostgroup}}

@item @strong{--sshlogin} @emph{[@@hostgroups/][ncpus/]sshlogin[,[@@hostgroups/][ncpus/]sshlogin[,...]]}
@anchor{@strong{--sshlogin} @emph{[@@hostgroups/][ncpus/]sshlogin[@comma{}[@@hostgroups/][ncpus/]sshlogin[@comma{}...]]}}

@item @strong{--sshlogin} @emph{@@hostgroup}
@anchor{@strong{--sshlogin} @emph{@@hostgroup}}

Distribute jobs to remote computers. The jobs will be run on a list of
remote computers.

If @emph{hostgroups} is given, the @emph{sshlogin} will be added to that
hostgroup. Multiple hostgroups are separated by '+'. The @emph{sshlogin}
will always be added to a hostgroup named the same as @emph{sshlogin}.

If only the @emph{@@hostgroup} is given, only the sshlogins in that
hostgroup will be used. Multiple @emph{@@hostgroup} can be given.

GNU @strong{parallel} will determine the number of CPUs on the remote
computers and run the number of jobs as specified by @strong{-j}.  If the
number @emph{ncpus} is given GNU @strong{parallel} will use this number for
number of CPUs on the host. Normally @emph{ncpus} will not be
needed.

An @emph{sshlogin} is of the form:

@verbatim
  [sshcommand [options]] [username@]hostname
@end verbatim

The sshlogin must not require a password (@strong{ssh-agent},
@strong{ssh-copy-id}, and @strong{sshpass} may help with that).

The sshlogin ':' is special, it means 'no ssh' and will therefore run
on the local computer.

The sshlogin '..' is special, it read sshlogins from ~/.parallel/sshloginfile or
$XDG_CONFIG_HOME/parallel/sshloginfile

The sshlogin '-' is special, too, it read sshlogins from stdin
(standard input).

To specify more sshlogins separate the sshlogins by comma, newline (in
the same string), or repeat the options multiple times.

For examples: see @strong{--sshloginfile}.

The remote host must have GNU @strong{parallel} installed.

@strong{--sshlogin} is known to cause problems with @strong{-m} and @strong{-X}.

@strong{--sshlogin} is often used with @strong{--transferfile}, @strong{--return},
@strong{--cleanup}, and @strong{--trc}.

@item @strong{--sshloginfile} @emph{filename}
@anchor{@strong{--sshloginfile} @emph{filename}}

@item @strong{--slf} @emph{filename}
@anchor{@strong{--slf} @emph{filename}}

File with sshlogins. The file consists of sshlogins on separate
lines. Empty lines and lines starting with '#' are ignored. Example:

@verbatim
  server.example.com
  username@server2.example.com
  8/my-8-cpu-server.example.com
  2/my_other_username@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 myusername hexacpu.example.net
  # Use a different ssh program with default number of CPUs
  //usr/local/bin/myssh -p 2222 -l myusername hexacpu
  # Use a different ssh program with 6 CPUs
  6//usr/local/bin/myssh -p 2222 -l myusername hexacpu
  # Assume 16 CPUs on the local computer
  16/:
  # Put server1 in hostgroup1
  @hostgroup1/server1
  # Put myusername@server2 in hostgroup1+hostgroup2
  @hostgroup1+hostgroup2/myusername@server2
  # Force 4 CPUs and put 'ssh -p 2222 server3' in hostgroup1
  @hostgroup1/4/ssh -p 2222 server3
@end verbatim

When using a different ssh program the last argument must be the hostname.

Multiple @strong{--sshloginfile} are allowed.

GNU @strong{parallel} will first look for the file in current dir; if that
fails it look for the file in ~/.parallel.

The sshloginfile '..' is special, it read sshlogins from
~/.parallel/sshloginfile

The sshloginfile '.' is special, it read sshlogins from
/etc/parallel/sshloginfile

The sshloginfile '-' is special, too, it read sshlogins from stdin
(standard input).

If the sshloginfile is changed it will be re-read when a job finishes
though at most once per second. This makes it possible to add and
remove hosts while running.

This can be used to have a daemon that updates the sshloginfile to
only contain servers that are up:

@verbatim
    cp original.slf tmp2.slf
    while [ 1 ] ; do
      nice parallel --nonall -j0 -k --slf original.slf \
        --tag echo | perl 's/\t$//' > tmp.slf
      if diff tmp.slf tmp2.slf; then
        mv tmp.slf tmp2.slf
      fi
      sleep 10
    done &
    parallel --slf tmp2.slf ...
@end verbatim

@item @strong{--slotreplace} @emph{replace-str}
@anchor{@strong{--slotreplace} @emph{replace-str}}

Use the replacement string @emph{replace-str} instead of @strong{@{%@}} for
job slot number.

@item @strong{--silent}
@anchor{@strong{--silent}}

Silent.  The job to be run will not be printed. This is the default.
Can be reversed with @strong{-v}.

@item @strong{--tty}
@anchor{@strong{--tty}}

Open terminal tty. If GNU @strong{parallel} is used for starting a program
that accesses the tty (such as an interactive program) then this
option may be needed. It will default to starting only one job at a
time (i.e. @strong{-j1}), not buffer the output (i.e. @strong{-u}), and it will
open a tty for the job.

You can of course override @strong{-j1} and @strong{-u}.

Using @strong{--tty} unfortunately means that GNU @strong{parallel} cannot kill
the jobs (with @strong{--timeout}, @strong{--memfree}, or @strong{--halt}). This is due
to GNU @strong{parallel} giving each child its own process group, which is
then killed. Process groups are dependant on the tty.

@item @strong{--tag}
@anchor{@strong{--tag}}

Tag lines with arguments. Each output line will be prepended with the
arguments and TAB (\t). When combined with @strong{--onall} or @strong{--nonall}
the lines will be prepended with the sshlogin instead.

@strong{--tag} is ignored when using @strong{-u}.

@item @strong{--tagstring} @emph{str}
@anchor{@strong{--tagstring} @emph{str}}

Tag lines with a string. Each output line will be prepended with
@emph{str} and TAB (\t). @emph{str} can contain replacement strings such as
@strong{@{@}}.

@strong{--tagstring} is ignored when using @strong{-u}, @strong{--onall}, and @strong{--nonall}.

@item @strong{--tee}
@anchor{@strong{--tee}}

Pipe all data to all jobs. Used with @strong{--pipe}/@strong{--pipepart} and
@strong{:::}.

@verbatim
  seq 1000 | parallel --pipe --tee -v wc {} ::: -w -l -c
@end verbatim

How many numbers in 1..1000 contain 0..9, and how many bytes do they
fill:

@verbatim
  seq 1000 | parallel --pipe --tee --tag \
    'grep {1} | wc {2}' ::: {0..9} ::: -l -c
@end verbatim

How many words contain a..z and how many bytes do they fill?

@verbatim
  parallel -a /usr/share/dict/words --pipepart --tee --tag \
    'grep {1} | wc {2}' ::: {a..z} ::: -l -c
@end verbatim

@item @strong{--termseq} @emph{sequence}
@anchor{@strong{--termseq} @emph{sequence}}

Termination sequence. When a job is killed due to @strong{--timeout},
@strong{--memfree}, @strong{--halt}, or abnormal termination of GNU @strong{parallel},
@emph{sequence} determines how the job is killed. The default is:

@verbatim
    TERM,200,TERM,100,TERM,50,KILL,25
@end verbatim

which sends a TERM signal, waits 200 ms, sends another TERM signal,
waits 100 ms, sends another TERM signal, waits 50 ms, sends a KILL
signal, waits 25 ms, and exits. GNU @strong{parallel} detects if a process
dies before the waiting time is up.

@item @strong{--tmpdir} @emph{dirname}
@anchor{@strong{--tmpdir} @emph{dirname}}

Directory for temporary files. GNU @strong{parallel} normally buffers output
into temporary files in /tmp. By setting @strong{--tmpdir} you can use a
different dir for the files. Setting @strong{--tmpdir} is equivalent to
setting $TMPDIR.

@item @strong{--tmux} (Long beta testing)
@anchor{@strong{--tmux} (Long beta testing)}

Use @strong{tmux} for output. Start a @strong{tmux} session and run each job in a
window in that session. No other output will be produced.

@item @strong{--tmuxpane} (Long beta testing)
@anchor{@strong{--tmuxpane} (Long beta testing)}

Use @strong{tmux} for output but put output into panes in the first window.
Useful if you want to monitor the progress of less than 100 concurrent
jobs.

@item @strong{--timeout} @emph{duration}
@anchor{@strong{--timeout} @emph{duration}}

Time out for command. If the command runs for longer than @emph{duration}
seconds it will get killed as per @strong{--termseq}.

If @emph{duration} is followed by a % then the timeout will dynamically be
computed as a percentage of the median average runtime of successful
jobs. Only values > 100% will make sense.

@emph{duration} is normally in seconds, but can be floats postfixed with
@strong{s}, @strong{m}, @strong{h}, or @strong{d} which would multiply the float by 1, 60,
3600, or 86400. Thus these are equivalent: @strong{--timeout 100000} and
@strong{--timeout 1d3.5h16.6m4s}.

@item @strong{--verbose}
@anchor{@strong{--verbose}}

@item @strong{-t}
@anchor{@strong{-t}}

Print the job to be run on stderr (standard error).

See also @strong{-v}, @strong{-p}.

@item @strong{--transfer}
@anchor{@strong{--transfer}}

Transfer files to remote computers. Shorthand for: @strong{--transferfile @{@}}.

@item @strong{--transferfile} @emph{filename}
@anchor{@strong{--transferfile} @emph{filename}}

@item @strong{--tf} @emph{filename}
@anchor{@strong{--tf} @emph{filename}}

@strong{--transferfile} is used with @strong{--sshlogin} to transfer files to the
remote computers. The files will be transferred using @strong{rsync} and
will be put relative to the default work dir. If the path contains /./
the remaining path will be relative to the work dir. E.g.

@verbatim
  echo foo/bar.txt | parallel --transferfile {} \
    --sshlogin server.example.com wc
@end verbatim

This will transfer the file @emph{foo/bar.txt} to the computer
@emph{server.example.com} to the file @emph{$HOME/foo/bar.txt} before running
@strong{wc foo/bar.txt} on @emph{server.example.com}.

@verbatim
  echo /tmp/foo/bar.txt | parallel --transferfile {} \
    --sshlogin server.example.com wc
@end verbatim

This will transfer the file @emph{/tmp/foo/bar.txt} to the computer
@emph{server.example.com} to the file @emph{/tmp/foo/bar.txt} before running
@strong{wc /tmp/foo/bar.txt} on @emph{server.example.com}.

@verbatim
  echo /tmp/./foo/bar.txt | parallel --transferfile {} \
    --sshlogin server.example.com wc {= s:.*/./:./: =}
@end verbatim

This will transfer the file @emph{/tmp/foo/bar.txt} to the computer
@emph{server.example.com} to the file @emph{foo/bar.txt} before running
@strong{wc ./foo/bar.txt} on @emph{server.example.com}.

@strong{--transferfile} is often used with @strong{--return} and @strong{--cleanup}. A
shorthand for @strong{--transferfile @{@}} is @strong{--transfer}.

@strong{--transferfile} is ignored when used with @strong{--sshlogin :} or when
not used with @strong{--sshlogin}.

@item @strong{--trc} @emph{filename}
@anchor{@strong{--trc} @emph{filename}}

Transfer, Return, Cleanup. Shorthand for:

@strong{--transferfile @{@}} @strong{--return} @emph{filename} @strong{--cleanup}

@item @strong{--trim} <n|l|r|lr|rl>
@anchor{@strong{--trim} <n|l|r|lr|rl>}

Trim white space in input.

@table @asis
@item n
@anchor{n}

No trim. Input is not modified. This is the default.

@item l
@anchor{l}

Left trim. Remove white space from start of input. E.g. " a bc " -> "a bc ".

@item r
@anchor{r}

Right trim. Remove white space from end of input. E.g. " a bc " -> " a bc".

@item lr
@anchor{lr}

@item rl
@anchor{rl}

Both trim. Remove white space from both start and end of input. E.g. "
a bc " -> "a bc". This is the default if @strong{--colsep} is used.

@end table

@item @strong{--ungroup}
@anchor{@strong{--ungroup}}

@item @strong{-u}
@anchor{@strong{-u}}

Ungroup output.  Output is printed as soon as possible and bypasses
GNU @strong{parallel} internal processing. This may cause output from
different commands to be mixed thus should only be used if you do not
care about the output. Compare these:

@verbatim
  seq 4 | parallel -j0 \
    'sleep {};echo -n start{};sleep {};echo {}end'
  seq 4 | parallel -u -j0 \
    'sleep {};echo -n start{};sleep {};echo {}end'
@end verbatim

It also disables @strong{--tag}. GNU @strong{parallel} outputs faster with
@strong{-u}. Compare the speeds of these:

@verbatim
  parallel seq ::: 300000000 >/dev/null
  parallel -u seq ::: 300000000 >/dev/null
  parallel --line-buffer seq ::: 300000000 >/dev/null
@end verbatim

Can be reversed with @strong{--group}.

See also: @strong{--line-buffer} @strong{--group}

@item @strong{--extensionreplace} @emph{replace-str}
@anchor{@strong{--extensionreplace} @emph{replace-str}}

@item @strong{--er} @emph{replace-str}
@anchor{@strong{--er} @emph{replace-str}}

Use the replacement string @emph{replace-str} instead of @strong{@{.@}} for input
line without extension.

@item @strong{--use-sockets-instead-of-threads}
@anchor{@strong{--use-sockets-instead-of-threads}}

@item @strong{--use-cores-instead-of-threads}
@anchor{@strong{--use-cores-instead-of-threads}}

@item @strong{--use-cpus-instead-of-cores} (obsolete)
@anchor{@strong{--use-cpus-instead-of-cores} (obsolete)}

Determine how GNU @strong{parallel} counts the number of CPUs. GNU
@strong{parallel} uses this number when the number of jobslots is computed
relative to the number of CPUs (e.g. 100% or +1).

CPUs can be counted in three different ways:

@table @asis
@item sockets
@anchor{sockets}

The number of filled CPU sockets (i.e. the number of physical chips).

@item cores
@anchor{cores}

The number of physical cores (i.e. the number of physical compute
cores).

@item threads
@anchor{threads}

The number of hyperthreaded cores (i.e. the number of virtual
cores - with some of them possibly being hyperthreaded)

@end table

Normally the number of CPUs is computed as the number of CPU
threads. With @strong{--use-sockets-instead-of-threads} or
@strong{--use-cores-instead-of-threads} you can force it to be computed as
the number of filled sockets or number of cores instead.

Most users will not need these options.

@strong{--use-cpus-instead-of-cores} is a (misleading) alias for
@strong{--use-sockets-instead-of-threads} and is kept for backwards
compatibility.

@item @strong{-v}
@anchor{@strong{-v}}

Verbose.  Print the job to be run on stdout (standard output). Can be reversed
with @strong{--silent}. See also @strong{-t}.

Use @strong{-v} @strong{-v} to print the wrapping ssh command when running remotely.

@item @strong{--version}
@anchor{@strong{--version}}

@item @strong{-V}
@anchor{@strong{-V}}

Print the version GNU @strong{parallel} and exit.

@item @strong{--workdir} @emph{mydir}
@anchor{@strong{--workdir} @emph{mydir}}

@item @strong{--wd} @emph{mydir}
@anchor{@strong{--wd} @emph{mydir}}

Files transferred using @strong{--transferfile} and @strong{--return} will be
relative to @emph{mydir} on remote computers, and the command will be
executed in the dir @emph{mydir}.

The special @emph{mydir} value @strong{...} will create working dirs under
@strong{~/.parallel/tmp/} on the remote computers. If @strong{--cleanup} is given
these dirs will be removed.

The special @emph{mydir} value @strong{.} uses the current working dir.  If the
current working dir is beneath your home dir, the value @strong{.} is
treated as the relative path to your home dir. This means that if your
home dir is different on remote computers (e.g. if your login is
different) the relative path will still be relative to your home dir.

To see the difference try:

@verbatim
  parallel -S server pwd ::: ""
  parallel --wd . -S server pwd ::: ""
  parallel --wd ... -S server pwd ::: ""
@end verbatim

@emph{mydir} can contain GNU @strong{parallel}'s replacement strings.

@item @strong{--wait}
@anchor{@strong{--wait}}

Wait for all commands to complete.

Used with @strong{--semaphore} or @strong{--sqlmaster}.

See also @strong{man sem}.

@item @strong{-X}
@anchor{@strong{-X}}

Multiple arguments with context replace. Insert as many arguments as
the command line length permits. If multiple jobs are being run in
parallel: distribute the arguments evenly among the jobs. Use @strong{-j1}
to avoid this.

If @strong{@{@}} is not used the arguments will be appended to the line.  If
@strong{@{@}} is used as part of a word (like @emph{pic@{@}.jpg}) then the whole
word will be repeated. If @strong{@{@}} is used multiple times each @strong{@{@}} will
be replaced with the arguments.

Normally @strong{-X} will do the right thing, whereas @strong{-m} can give
unexpected results if @strong{@{@}} is used as part of a word.

Support for @strong{-X} with @strong{--sshlogin} is limited and may fail.

See also @strong{-m}.

@item @strong{--exit}
@anchor{@strong{--exit}}

@item @strong{-x}
@anchor{@strong{-x}}

Exit if the size (see the @strong{-s} option) is exceeded.

@end table

@node EXAMPLE: Working as xargs -n1. Argument appending
@chapter EXAMPLE: Working as xargs -n1. Argument appending

GNU @strong{parallel} can work similar to @strong{xargs -n1}.

To compress all html files using @strong{gzip} run:

@verbatim
  find . -name '*.html' | parallel gzip --best
@end verbatim

If the file names may contain a newline use @strong{-0}. Substitute FOO BAR with
FUBAR in all files in this dir and subdirs:

@verbatim
  find . -type f -print0 | \
    parallel -q0 perl -i -pe 's/FOO BAR/FUBAR/g'
@end verbatim

Note @strong{-q} is needed because of the space in 'FOO BAR'.

@node EXAMPLE: Simple network scanner
@chapter EXAMPLE: Simple network scanner

@strong{prips} can generate IP-addresses from CIDR notation. With GNU
@strong{parallel} you can build a simple network scanner to see which
addresses respond to @strong{ping}:

@verbatim
  prips 130.229.16.0/20 | \
    parallel --timeout 2 -j0 \
      'ping -c 1 {} >/dev/null && echo {}' 2>/dev/null
@end verbatim

@node EXAMPLE: Reading arguments from command line
@chapter EXAMPLE: Reading arguments from command line

GNU @strong{parallel} can take the arguments from command line instead of
stdin (standard input). To compress all html files in the current dir
using @strong{gzip} run:

@verbatim
  parallel gzip --best ::: *.html
@end verbatim

To convert *.wav to *.mp3 using LAME running one process per CPU run:

@verbatim
  parallel lame {} -o {.}.mp3 ::: *.wav
@end verbatim

@node EXAMPLE: Inserting multiple arguments
@chapter EXAMPLE: Inserting multiple arguments

When moving a lot of files like this: @strong{mv *.log destdir} you will
sometimes get the error:

@verbatim
  bash: /bin/mv: Argument list too long
@end verbatim

because there are too many files. You can instead do:

@verbatim
  ls | grep -E '\.log$' | parallel mv {} destdir
@end verbatim

This will run @strong{mv} for each file. It can be done faster if @strong{mv} gets
as many arguments that will fit on the line:

@verbatim
  ls | grep -E '\.log$' | parallel -m mv {} destdir
@end verbatim

In many shells you can also use @strong{printf}:

@verbatim
  printf '%s\0' *.log | parallel -0 -m mv {} destdir
@end verbatim

@node EXAMPLE: Context replace
@chapter EXAMPLE: Context replace

To remove the files @emph{pict0000.jpg} .. @emph{pict9999.jpg} you could do:

@verbatim
  seq -w 0 9999 | parallel rm pict{}.jpg
@end verbatim

You could also do:

@verbatim
  seq -w 0 9999 | perl -pe 's/(.*)/pict$1.jpg/' | parallel -m rm
@end verbatim

The first will run @strong{rm} 10000 times, while the last will only run
@strong{rm} as many times needed to keep the command line length short
enough to avoid @strong{Argument list too long} (it typically runs 1-2 times).

You could also run:

@verbatim
  seq -w 0 9999 | parallel -X rm pict{}.jpg
@end verbatim

This will also only run @strong{rm} as many times needed to keep the command
line length short enough.

@node EXAMPLE: Compute intensive jobs and substitution
@chapter EXAMPLE: Compute intensive jobs and substitution

If ImageMagick is installed this will generate a thumbnail of a jpg
file:

@verbatim
  convert -geometry 120 foo.jpg thumb_foo.jpg
@end verbatim

This will run with number-of-cpus jobs in parallel for all jpg files
in a directory:

@verbatim
  ls *.jpg | parallel convert -geometry 120 {} thumb_{}
@end verbatim

To do it recursively use @strong{find}:

@verbatim
  find . -name '*.jpg' | \
    parallel convert -geometry 120 {} {}_thumb.jpg
@end verbatim

Notice how the argument has to start with @strong{@{@}} as @strong{@{@}} will include path
(e.g. running @strong{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 @strong{@{.@}} to avoid the extra .jpg in the file name. This command will
make files like ./foo/bar_thumb.jpg:

@verbatim
  find . -name '*.jpg' | \
    parallel convert -geometry 120 {} {.}_thumb.jpg
@end verbatim

@node EXAMPLE: Substitution and redirection
@chapter EXAMPLE: Substitution and redirection

This will generate an uncompressed version of .gz-files next to the .gz-file:

@verbatim
  parallel zcat {} ">"{.} ::: *.gz
@end verbatim

Quoting of > is necessary to postpone the redirection. Another
solution is to quote the whole command:

@verbatim
  parallel "zcat {} >{.}" ::: *.gz
@end verbatim

Other special shell characters (such as * ; $ > < | >> <<) also need
to be put in quotes, as they may otherwise be interpreted by the shell
and not given to GNU @strong{parallel}.

@node EXAMPLE: Composed commands
@chapter EXAMPLE: Composed commands

A job can consist of several commands. This will print the number of
files in each directory:

@verbatim
  ls | parallel 'echo -n {}" "; ls {}|wc -l'
@end verbatim

To put the output in a file called <name>.dir:

@verbatim
  ls | parallel '(echo -n {}" "; ls {}|wc -l) >{}.dir'
@end verbatim

Even small shell scripts can be run by GNU @strong{parallel}:

@verbatim
  find . | parallel 'a={}; name=${a##*/};' \
    'upper=$(echo "$name" | tr "[:lower:]" "[:upper:]");'\
    'echo "$name - $upper"'

  ls | parallel 'mv {} "$(echo {} | tr "[:upper:]" "[:lower:]")"'
@end verbatim

Given a list of URLs, list all URLs that fail to download. Print the
line number and the URL.

@verbatim
  cat urlfile | parallel "wget {} 2>/dev/null || grep -n {} urlfile"
@end verbatim

Create a mirror directory with the same filenames except all files and
symlinks are empty files.

@verbatim
  cp -rs /the/source/dir mirror_dir
  find mirror_dir -type l | parallel -m rm {} '&&' touch {}
@end verbatim

Find the files in a list that do not exist

@verbatim
  cat file_list | parallel 'if [ ! -e {} ] ; then echo {}; fi'
@end verbatim

@node EXAMPLE: Composed command with multiple input sources
@chapter EXAMPLE: Composed command with multiple input sources

You have a dir with files named as 24 hours in 5 minute intervals:
00:00, 00:05, 00:10 .. 23:55. You want to find the files missing:

@verbatim
  parallel [ -f {1}:{2} ] "||" echo {1}:{2} does not exist \
    ::: {00..23} ::: {00..55..5}
@end verbatim

@node EXAMPLE: Calling Bash functions
@chapter EXAMPLE: Calling Bash functions

If the composed command is longer than a line, it becomes hard to
read. In Bash you can use functions. Just remember to @strong{export -f} the
function.

@verbatim
  doit() {
    echo Doing it for $1
    sleep 2
    echo Done with $1
  }
  export -f doit
  parallel doit ::: 1 2 3

  doubleit() {
    echo Doing it for $1 $2
    sleep 2
    echo Done with $1 $2
  }
  export -f doubleit
  parallel doubleit ::: 1 2 3 ::: a b
@end verbatim

To do this on remote servers you need to transfer the function using
@strong{--env}:

@verbatim
  parallel --env doit -S server doit ::: 1 2 3
  parallel --env doubleit -S server doubleit ::: 1 2 3 ::: a b
@end verbatim

If your environment (aliases, variables, and functions) is small you
can copy the full environment without having to @strong{export -f}
anything. See @strong{env_parallel}.

@node EXAMPLE: Function tester
@chapter EXAMPLE: Function tester

To test a program with different parameters:

@verbatim
  tester() {
    if (eval "$@") >&/dev/null; then
      perl -e 'printf "\033[30;102m[ OK ]\033[0m @ARGV\n"' "$@"
    else
      perl -e 'printf "\033[30;101m[FAIL]\033[0m @ARGV\n"' "$@"
    fi
  }
  export -f tester
  parallel tester my_program ::: arg1 arg2
  parallel tester exit ::: 1 0 2 0
@end verbatim

If @strong{my_program} fails a red FAIL will be printed followed by the failing
command; otherwise a green OK will be printed followed by the command.

@node EXAMPLE: Log rotate
@chapter EXAMPLE: Log rotate

Log rotation renames a logfile to an extension with a higher number:
log.1 becomes log.2, log.2 becomes log.3, and so on. The oldest log is
removed. To avoid overwriting files the process starts backwards from
the high number to the low number.  This will keep 10 old versions of
the log:

@verbatim
  seq 9 -1 1 | parallel -j1 mv log.{} log.'{= $_++ =}'
  mv log log.1
@end verbatim

@node EXAMPLE: Removing file extension when processing files
@chapter EXAMPLE: Removing file extension when processing files

When processing files removing the file extension using @strong{@{.@}} is
often useful.

Create a directory for each zip-file and unzip it in that dir:

@verbatim
  parallel 'mkdir {.}; cd {.}; unzip ../{}' ::: *.zip
@end verbatim

Recompress all .gz files in current directory using @strong{bzip2} running 1
job per CPU in parallel:

@verbatim
  parallel "zcat {} | bzip2 >{.}.bz2 && rm {}" ::: *.gz
@end verbatim

Convert all WAV files to MP3 using LAME:

@verbatim
  find sounddir -type f -name '*.wav' | parallel lame {} -o {.}.mp3
@end verbatim

Put all converted in the same directory:

@verbatim
  find sounddir -type f -name '*.wav' | \
    parallel lame {} -o mydir/{/.}.mp3
@end verbatim

@node EXAMPLE: Removing strings from the argument
@chapter EXAMPLE: Removing strings from the argument

If you have directory with tar.gz files and want these extracted in
the corresponding dir (e.g foo.tar.gz will be extracted in the dir
foo) you can do:

@verbatim
  parallel --plus 'mkdir {..}; tar -C {..} -xf {}' ::: *.tar.gz
@end verbatim

If you want to remove a different ending, you can use @{%string@}:

@verbatim
  parallel --plus echo {%_demo} ::: mycode_demo keep_demo_here
@end verbatim

You can also remove a starting string with @{#string@}

@verbatim
  parallel --plus echo {#demo_} ::: demo_mycode keep_demo_here
@end verbatim

To remove a string anywhere you can use regular expressions with
@{/regexp/replacement@} and leave the replacement empty:

@verbatim
  parallel --plus echo {/demo_/} ::: demo_mycode remove_demo_here
@end verbatim

@node EXAMPLE: Download 24 images for each of the past 30 days
@chapter EXAMPLE: Download 24 images for each of the past 30 days

Let us assume a website stores images like:

@verbatim
  http://www.example.com/path/to/YYYYMMDD_##.jpg
@end verbatim

where YYYYMMDD is the date and ## is the number 01-24. This will
download images for the past 30 days:

@verbatim
  getit() {
    date=$(date -d "today -$1 days" +%Y%m%d)
    num=$2
    echo wget http://www.example.com/path/to/${date}_${num}.jpg
  }
  export -f getit
  
  parallel getit ::: $(seq 30) ::: $(seq -w 24)
@end verbatim

@strong{$(date -d "today -$1 days" +%Y%m%d)} will give the dates in
YYYYMMDD with @strong{$1} days subtracted.

@node EXAMPLE: Download world map from NASA
@chapter EXAMPLE: Download world map from NASA

NASA provides tiles to download on earthdata.nasa.gov. Download tiles
for Blue Marble world map and create a 10240x20480 map.

@verbatim
  base=https://map1a.vis.earthdata.nasa.gov/wmts-geo/wmts.cgi
  service="SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0"
  layer="LAYER=BlueMarble_ShadedRelief_Bathymetry"
  set="STYLE=&TILEMATRIXSET=EPSG4326_500m&TILEMATRIX=5"
  tile="TILEROW={1}&TILECOL={2}"
  format="FORMAT=image%2Fjpeg"
  url="$base?$service&$layer&$set&$tile&$format"

  parallel -j0 -q wget "$url" -O {1}_{2}.jpg ::: {0..19} ::: {0..39}
  parallel eval convert +append {}_{0..39}.jpg line{}.jpg ::: {0..19}
  convert -append line{0..19}.jpg world.jpg
@end verbatim

@node EXAMPLE: Download Apollo-11 images from NASA using jq
@chapter EXAMPLE: Download Apollo-11 images from NASA using jq

Search NASA using their API to get JSON for images related to 'apollo
11' and has 'moon landing' in the description.

The search query returns JSON containing URLs to JSON containing
collections of pictures. One of the pictures in each of these
collection is @emph{large}.

@strong{wget} is used to get the JSON for the search query. @strong{jq} is then
used to extract the URLs of the collections. @strong{parallel} then calls
@strong{wget} to get each collection, which is passed to @strong{jq} to extract
the URLs of all images. @strong{grep} filters out the @emph{large} images, and
@strong{parallel} finally uses @strong{wget} to fetch the images.

@verbatim
  base="https://images-api.nasa.gov/search"
  q="q=apollo 11"
  description="description=moon landing"
  media_type="media_type=image"
  wget -O - "$base?$q&$description&$media_type" |
    jq -r .collection.items[].href |
    parallel wget -O - |
    jq -r .[] |
    grep large |
    parallel wget
@end verbatim

@node EXAMPLE: Download video playlist in parallel
@chapter EXAMPLE: Download video playlist in parallel

@strong{youtube-dl} is an excellent tool to download videos. It can,
however, not download videos in parallel. This takes a playlist and
downloads 10 videos in parallel.

@verbatim
  url='youtu.be/watch?v=0wOf2Fgi3DE&list=UU_cznB5YZZmvAmeq7Y3EriQ'
  export url
  youtube-dl --flat-playlist "https://$url" |
    parallel --tagstring {#} --lb -j10 \
      youtube-dl --playlist-start {#} --playlist-end {#} '"https://$url"'
@end verbatim

@node EXAMPLE: Prepend last modified date (ISO8601) to file name
@chapter EXAMPLE: Prepend last modified date (ISO8601) to file name

@verbatim
  parallel mv {} '{= $a=pQ($_); $b=$_;' \
    '$_=qx{date -r "$a" +%FT%T}; chomp; $_="$_ $b" =}' ::: *
@end verbatim

@strong{@{=} and @strong{=@}} mark a perl expression. @strong{pQ} perl-quotes the
string. @strong{date +%FT%T} is the date in ISO8601 with time.

@node EXAMPLE: Save output in ISO8601 dirs
@chapter EXAMPLE: Save output in ISO8601 dirs

Save output from @strong{ps aux} every second into dirs named
yyyy-mm-ddThh:mm:ss+zz:zz.

@verbatim
  seq 1000 | parallel -N0 -j1 --delay 1 \
    --results '{= $_=`date -Isec`; chomp=}/' ps aux
@end verbatim

@node EXAMPLE: Digital clock with "blinking" :
@chapter EXAMPLE: Digital clock with "blinking" :

The : in a digital clock blinks. To make every other line have a ':'
and the rest a ' ' a perl expression is used to look at the 3rd input
source. If the value modulo 2 is 1: Use ":" otherwise use " ":

@verbatim
  parallel -k echo {1}'{=3 $_=$_%2?":":" "=}'{2}{3} \
    ::: {0..12} ::: {0..5} ::: {0..9}
@end verbatim

@node EXAMPLE: Aggregating content of files
@chapter EXAMPLE: Aggregating content of files

This:

@verbatim
  parallel --header : echo x{X}y{Y}z{Z} \> x{X}y{Y}z{Z} \
  ::: X {1..5} ::: Y {01..10} ::: Z {1..5}
@end verbatim

will generate the files x1y01z1 .. x5y10z5. If you want to aggregate
the output grouping on x and z you can do this:

@verbatim
  parallel eval 'cat {=s/y01/y*/=} > {=s/y01//=}' ::: *y01*
@end verbatim

For all values of x and z it runs commands like:

@verbatim
  cat x1y*z1 > x1z1
@end verbatim

So you end up with x1z1 .. x5z5 each containing the content of all
values of y.

@node EXAMPLE: Breadth first parallel web crawler/mirrorer
@chapter EXAMPLE: Breadth first parallel web crawler/mirrorer

This script below will crawl and mirror a URL in parallel.  It
downloads first pages that are 1 click down, then 2 clicks down, then
3; instead of the normal depth first, where the first link link on
each page is fetched first.

Run like this:

@verbatim
  PARALLEL=-j100 ./parallel-crawl http://gatt.org.yeslab.org/
@end verbatim

Remove the @strong{wget} part if you only want a web crawler.

It works by fetching a page from a list of URLs and looking for links
in that page that are within the same starting URL and that have not
already been seen. These links are added to a new queue. When all the
pages from the list is done, the new queue is moved to the list of
URLs and the process is started over until no unseen links are found.

@verbatim
  #!/bin/bash

  # E.g. http://gatt.org.yeslab.org/
  URL=$1
  # Stay inside the start dir
  BASEURL=$(echo $URL | perl -pe 's:#.*::; s:(//.*/)[^/]*:$1:')
  URLLIST=$(mktemp urllist.XXXX)
  URLLIST2=$(mktemp urllist.XXXX)
  SEEN=$(mktemp seen.XXXX)

  # Spider to get the URLs
  echo $URL >$URLLIST
  cp $URLLIST $SEEN

  while [ -s $URLLIST ] ; do
    cat $URLLIST |
      parallel lynx -listonly -image_links -dump {} \; \
        wget -qm -l1 -Q1 {} \; echo Spidered: {} \>\&2 |
        perl -ne 's/#.*//; s/\s+\d+.\s(\S+)$/$1/ and
          do { $seen{$1}++ or print }' |
      grep -F $BASEURL |
      grep -v -x -F -f $SEEN | tee -a $SEEN > $URLLIST2
    mv $URLLIST2 $URLLIST
  done

  rm -f $URLLIST $URLLIST2 $SEEN
@end verbatim

@node EXAMPLE: Process files from a tar file while unpacking
@chapter EXAMPLE: Process files from a tar file while unpacking

If the files to be processed are in a tar file then unpacking one file
and processing it immediately may be faster than first unpacking all
files.

@verbatim
  tar xvf foo.tgz | perl -ne 'print $l;$l=$_;END{print $l}' | \
    parallel echo
@end verbatim

The Perl one-liner is needed to make sure the file is complete before
handing it to GNU @strong{parallel}.

@node EXAMPLE: Rewriting a for-loop and a while-read-loop
@chapter EXAMPLE: Rewriting a for-loop and a while-read-loop

for-loops like this:

@verbatim
  (for x in `cat list` ; do
    do_something $x
  done) | process_output
@end verbatim

and while-read-loops like this:

@verbatim
  cat list | (while read x ; do
    do_something $x
  done) | process_output
@end verbatim

can be written like this:

@verbatim
  cat list | parallel do_something | process_output
@end verbatim

For example: Find which host name in a list has IP address 1.2.3 4:

@verbatim
  cat hosts.txt | parallel -P 100 host | grep 1.2.3.4
@end verbatim

If the processing requires more steps the for-loop like this:

@verbatim
  (for x in `cat list` ; do
    no_extension=${x%.*};
    do_step1 $x scale $no_extension.jpg
    do_step2 <$x $no_extension
  done) | process_output
@end verbatim

and while-loops like this:

@verbatim
  cat list | (while read x ; do
    no_extension=${x%.*};
    do_step1 $x scale $no_extension.jpg
    do_step2 <$x $no_extension
  done) | process_output
@end verbatim

can be written like this:

@verbatim
  cat list | parallel "do_step1 {} scale {.}.jpg ; do_step2 <{} {.}" |\
    process_output
@end verbatim

If the body of the loop is bigger, it improves readability to use a function:

@verbatim
  (for x in `cat list` ; do
    do_something $x
    [... 100 lines that do something with $x ...]
  done) | process_output

  cat list | (while read x ; do
    do_something $x
    [... 100 lines that do something with $x ...]
  done) | process_output
@end verbatim

can both be rewritten as:

@verbatim
  doit() {
    x=$1
    do_something $x
    [... 100 lines that do something with $x ...]
  }
  export -f doit
  cat list | parallel doit
@end verbatim

@node EXAMPLE: Rewriting nested for-loops
@chapter EXAMPLE: Rewriting nested for-loops

Nested for-loops like this:

@verbatim
  (for x in `cat xlist` ; do
    for y in `cat ylist` ; do
      do_something $x $y
    done
  done) | process_output
@end verbatim

can be written like this:

@verbatim
  parallel do_something {1} {2} :::: xlist ylist | process_output
@end verbatim

Nested for-loops like this:

@verbatim
  (for colour in red green blue ; do
    for size in S M L XL XXL ; do
      echo $colour $size
    done
  done) | sort
@end verbatim

can be written like this:

@verbatim
  parallel echo {1} {2} ::: red green blue ::: S M L XL XXL | sort
@end verbatim

@node EXAMPLE: Finding the lowest difference between files
@chapter EXAMPLE: Finding the lowest difference between files

@strong{diff} is good for finding differences in text files. @strong{diff | wc -l}
gives an indication of the size of the difference. To find the
differences between all files in the current dir do:

@verbatim
  parallel --tag 'diff {1} {2} | wc -l' ::: * ::: * | sort -nk3
@end verbatim

This way it is possible to see if some files are closer to other
files.

@node EXAMPLE: for-loops with column names
@chapter EXAMPLE: for-loops with column names

When doing multiple nested for-loops it can be easier to keep track of
the loop variable if is is named instead of just having a number. Use
@strong{--header :} to let the first argument be an named alias for the
positional replacement string:

@verbatim
  parallel --header : echo {colour} {size} \
    ::: colour red green blue ::: size S M L XL XXL
@end verbatim

This also works if the input file is a file with columns:

@verbatim
  cat addressbook.tsv | \
    parallel --colsep '\t' --header : echo {Name} {E-mail address}
@end verbatim

@node EXAMPLE: All combinations in a list
@chapter EXAMPLE: All combinations in a list

GNU @strong{parallel} makes all combinations when given two lists.

To make all combinations in a single list with unique values, you
repeat the list and use replacement string @strong{@{choose_k@}}:

@verbatim
  parallel --plus echo {choose_k} ::: A B C D ::: A B C D

  parallel --plus echo 2{2choose_k} 1{1choose_k} ::: A B C D ::: A B C D
@end verbatim

@strong{@{choose_k@}} works for any number of input sources:

@verbatim
  parallel --plus echo {choose_k} ::: A B C D ::: A B C D ::: A B C D
@end verbatim

@node EXAMPLE: From a to b and b to c
@chapter EXAMPLE: From a to b and b to c

Assume you have input like:

@verbatim
  aardvark
  babble
  cab
  dab
  each
@end verbatim

and want to run combinations like:

@verbatim
  aardvark babble
  babble cab
  cab dab
  dab each
@end verbatim

If the input is in the file in.txt:

@verbatim
  parallel echo {1} - {2} ::::+ <(head -n -1 in.txt) <(tail -n +2 in.txt)
@end verbatim

If the input is in the array $a here are two solutions:

@verbatim
  seq $((${#a[@]}-1)) | \
    env_parallel --env a echo '${a[{=$_--=}]} - ${a[{}]}'
  parallel echo {1} - {2} ::: "${a[@]::${#a[@]}-1}" :::+ "${a[@]:1}"
@end verbatim

@node EXAMPLE: Count the differences between all files in a dir
@chapter EXAMPLE: Count the differences between all files in a dir

Using @strong{--results} the results are saved in /tmp/diffcount*.

@verbatim
  parallel --results /tmp/diffcount "diff -U 0 {1} {2} | \
    tail -n +3 |grep -v '^@'|wc -l" ::: * ::: *
@end verbatim

To see the difference between file A and file B look at the file
'/tmp/diffcount/1/A/2/B'.

@node EXAMPLE: Speeding up fast jobs
@chapter EXAMPLE: Speeding up fast jobs

Starting a job on the local machine takes around 10 ms. This can be a
big overhead if the job takes very few ms to run. Often you can group
small jobs together using @strong{-X} which will make the overhead less
significant. Compare the speed of these:

@verbatim
  seq -w 0 9999 | parallel touch pict{}.jpg
  seq -w 0 9999 | parallel -X touch pict{}.jpg
@end verbatim

If your program cannot take multiple arguments, then you can use GNU
@strong{parallel} to spawn multiple GNU @strong{parallel}s:

@verbatim
  seq -w 0 9999999 | \
    parallel -j10 -q -I,, --pipe parallel -j0 touch pict{}.jpg
@end verbatim

If @strong{-j0} normally spawns 252 jobs, then the above will try to spawn
2520 jobs. On a normal GNU/Linux system you can spawn 32000 jobs using
this technique with no problems. To raise the 32000 jobs limit raise
/proc/sys/kernel/pid_max to 4194303.

@node EXAMPLE: Using shell variables
@chapter EXAMPLE: Using shell variables

When using shell variables you need to quote them correctly as they
may otherwise be interpreted by the shell.

Notice the difference between:

@verbatim
  ARR=("My brother's 12\" records are worth <\$\$\$>"'!' Foo Bar)
  parallel echo ::: ${ARR[@]} # This is probably not what you want
@end verbatim

and:

@verbatim
  ARR=("My brother's 12\" records are worth <\$\$\$>"'!' Foo Bar)
  parallel echo ::: "${ARR[@]}"
@end verbatim

When using variables in the actual command that contains special
characters (e.g. space) you can quote them using @strong{'"$VAR"'} or using
"'s and @strong{-q}:

@verbatim
  VAR="My brother's 12\" records are worth <\$\$\$>"
  parallel -q echo "$VAR" ::: '!'
  export VAR
  parallel echo '"$VAR"' ::: '!'
@end verbatim

If @strong{$VAR} does not contain ' then @strong{"'$VAR'"} will also work
(and does not need @strong{export}):

@verbatim
  VAR="My 12\" records are worth <\$\$\$>"
  parallel echo "'$VAR'" ::: '!'
@end verbatim

If you use them in a function you just quote as you normally would do:

@verbatim
  VAR="My brother's 12\" records are worth <\$\$\$>"
  export VAR
  myfunc() { echo "$VAR" "$1"; }
  export -f myfunc
  parallel myfunc ::: '!'
@end verbatim

@node EXAMPLE: Group output lines
@chapter EXAMPLE: Group output lines

When running jobs that output data, you often do not want the output
of multiple jobs to run together. GNU @strong{parallel} defaults to grouping
the output of each job, so the output is printed when the job
finishes. If you want full lines to be printed while the job is
running you can use @strong{--line-buffer}. If you want output to be
printed as soon as possible you can use @strong{-u}.

Compare the output of:

@verbatim
  parallel wget --limit-rate=100k \
    https://ftpmirror.gnu.org/parallel/parallel-20{}0822.tar.bz2 \
    ::: {12..16}
  parallel --line-buffer wget --limit-rate=100k \
    https://ftpmirror.gnu.org/parallel/parallel-20{}0822.tar.bz2 \
    ::: {12..16}
  parallel -u wget --limit-rate=100k \
    https://ftpmirror.gnu.org/parallel/parallel-20{}0822.tar.bz2 \
    ::: {12..16}
@end verbatim

@node EXAMPLE: Tag output lines
@chapter EXAMPLE: Tag output lines

GNU @strong{parallel} groups the output lines, but it can be hard to see
where the different jobs begin. @strong{--tag} prepends the argument to make
that more visible:

@verbatim
  parallel --tag wget --limit-rate=100k \
    https://ftpmirror.gnu.org/parallel/parallel-20{}0822.tar.bz2 \
    ::: {12..16}
@end verbatim

@strong{--tag} works with @strong{--line-buffer} but not with @strong{-u}:

@verbatim
  parallel --tag --line-buffer wget --limit-rate=100k \
    https://ftpmirror.gnu.org/parallel/parallel-20{}0822.tar.bz2 \
    ::: {12..16}
@end verbatim

Check the uptime of the servers in @emph{~/.parallel/sshloginfile}:

@verbatim
  parallel --tag -S .. --nonall uptime
@end verbatim

@node EXAMPLE: Colorize output
@chapter EXAMPLE: Colorize output

Give each job a new color. Most terminals support ANSI colors with the
escape code "\033[30;3Xm" where 0 <= X <= 7:

@verbatim
    seq 10 | \
      parallel --tagstring '\033[30;3{=$_=++$::color%8=}m' seq {}
    parallel --rpl '{color} $_="\033[30;3".(++$::color%8)."m"' \
      --tagstring {color} seq {} ::: {1..10}
@end verbatim

To get rid of the initial \t (which comes from @strong{--tagstring}):

@verbatim
    ... | perl -pe 's/\t//'
@end verbatim

@node EXAMPLE: Keep order of output same as order of input
@chapter EXAMPLE: Keep order of output same as order of input

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. @strong{-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:

@verbatim
  cat textfile | parallel -k echo {} append_string
@end verbatim

If you remove @strong{-k} some of the lines may come out in the wrong order.

Another example is @strong{traceroute}:

@verbatim
  parallel traceroute ::: qubes-os.org debian.org freenetproject.org
@end verbatim

will give traceroute of qubes-os.org, 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:

@verbatim
  parallel -k traceroute ::: qubes-os.org debian.org freenetproject.org
@end verbatim

This will make sure the traceroute to qubes-os.org will be printed
first.

A bit more complex example is downloading a huge file in chunks in
parallel: Some internet connections will deliver more data if you
download files in parallel. For downloading files in parallel see:
"EXAMPLE: Download 10 images for each of the past 30 days". But if you
are downloading a big file you can download the file in chunks in
parallel.

To download byte 10000000-19999999 you can use @strong{curl}:

@verbatim
  curl -r 10000000-19999999 http://example.com/the/big/file >file.part
@end verbatim

To download a 1 GB file we need 100 10MB chunks downloaded and
combined in the correct order.

@verbatim
  seq 0 99 | parallel -k curl -r \
    {}0000000-{}9999999 http://example.com/the/big/file > file
@end verbatim

@node EXAMPLE: Parallel grep
@chapter EXAMPLE: Parallel grep

@strong{grep -r} greps recursively through directories. On multicore CPUs
GNU @strong{parallel} can often speed this up.

@verbatim
  find . -type f | parallel -k -j150% -n 1000 -m grep -H -n STRING {}
@end verbatim

This will run 1.5 job per CPU, and give 1000 arguments to @strong{grep}.

@node EXAMPLE: Grepping n lines for m regular expressions.
@chapter EXAMPLE: Grepping n lines for m regular expressions.

The simplest solution to grep a big file for a lot of regexps is:

@verbatim
  grep -f regexps.txt bigfile
@end verbatim

Or if the regexps are fixed strings:

@verbatim
  grep -F -f regexps.txt bigfile
@end verbatim

There are 3 limiting factors: CPU, RAM, and disk I/O.

RAM is easy to measure: If the @strong{grep} process takes up most of your
free memory (e.g. when running @strong{top}), then RAM is a limiting factor.

CPU is also easy to measure: If the @strong{grep} takes >90% CPU in @strong{top},
then the CPU is a limiting factor, and parallelization will speed this
up.

It is harder to see if disk I/O is the limiting factor, and depending
on the disk system it may be faster or slower to parallelize. The only
way to know for certain is to test and measure.

@menu
* Limiting factor@asis{:} RAM::
* Limiting factor@asis{:} CPU::
* Bigger problem::
@end menu

@node Limiting factor: RAM
@section Limiting factor: RAM

The normal @strong{grep -f regexs.txt bigfile} works no matter the size of
bigfile, but if regexps.txt is so big it cannot fit into memory, then
you need to split this.

@strong{grep -F} takes around 100 bytes of RAM and @strong{grep} takes about 500
bytes of RAM per 1 byte of regexp. So if regexps.txt is 1% of your
RAM, then it may be too big.

If you can convert your regexps into fixed strings do that. E.g. if
the lines you are looking for in bigfile all looks like:

@verbatim
  ID1 foo bar baz Identifier1 quux
  fubar ID2 foo bar baz Identifier2
@end verbatim

then your regexps.txt can be converted from:

@verbatim
  ID1.*Identifier1
  ID2.*Identifier2
@end verbatim

into:

@verbatim
  ID1 foo bar baz Identifier1
  ID2 foo bar baz Identifier2
@end verbatim

This way you can use @strong{grep -F} which takes around 80% less memory and
is much faster.

If it still does not fit in memory you can do this:

@verbatim
  parallel --pipepart -a regexps.txt --block 1M grep -Ff - -n bigfile | \
    sort -un | perl -pe 's/^\d+://'
@end verbatim

The 1M should be your free memory divided by the number of CPU threads and
divided by 200 for @strong{grep -F} and by 1000 for normal @strong{grep}. On
GNU/Linux you can do:

@verbatim
  free=$(awk '/^((Swap)?Cached|MemFree|Buffers):/ { sum += $2 }
              END { print sum }' /proc/meminfo)
  percpu=$((free / 200 / $(parallel --number-of-threads)))k

  parallel --pipepart -a regexps.txt --block $percpu --compress \
    grep -F -f - -n bigfile | \
    sort -un | perl -pe 's/^\d+://'
@end verbatim

If you can live with duplicated lines and wrong order, it is faster to do:

@verbatim
  parallel --pipepart -a regexps.txt --block $percpu --compress \
    grep -F -f - bigfile
@end verbatim

@node Limiting factor: CPU
@section Limiting factor: CPU

If the CPU is the limiting factor parallelization should be done on
the regexps:

@verbatim
  cat regexp.txt | parallel --pipe -L1000 --roundrobin --compress \
    grep -f - -n bigfile | \
    sort -un | perl -pe 's/^\d+://'
@end verbatim

The command will start one @strong{grep} per CPU and read @emph{bigfile} one
time per CPU, but as that is done in parallel, all reads except the
first will be cached in RAM. Depending on the size of @emph{regexp.txt} it
may be faster to use @strong{--block 10m} instead of @strong{-L1000}.

Some storage systems perform better when reading multiple chunks in
parallel. This is true for some RAID systems and for some network file
systems. To parallelize the reading of @emph{bigfile}:

@verbatim
  parallel --pipepart --block 100M -a bigfile -k --compress \
    grep -f regexp.txt
@end verbatim

This will split @emph{bigfile} into 100MB chunks and run @strong{grep} on each of
these chunks. To parallelize both reading of @emph{bigfile} and @emph{regexp.txt}
combine the two using @strong{--fifo}:

@verbatim
  parallel --pipepart --block 100M -a bigfile --fifo cat regexp.txt \
    \| parallel --pipe -L1000 --roundrobin grep -f - {}
@end verbatim

If a line matches multiple regexps, the line may be duplicated.

@node Bigger problem
@section Bigger problem

If the problem is too big to be solved by this, you are probably ready
for Lucene.

@node EXAMPLE: Using remote computers
@chapter EXAMPLE: Using remote computers

To run commands on a remote computer SSH needs to be set up and you
must be able to login without entering a password (The commands
@strong{ssh-copy-id}, @strong{ssh-agent}, and @strong{sshpass} may help you do that).

If you need to login to a whole cluster, you typically do not want to
accept the host key for every host. You want to accept them the first
time and be warned if they are ever changed. To do that:

@verbatim
  # Add the servers to the sshloginfile
  (echo servera; echo serverb) > .parallel/my_cluster
  # Make sure .ssh/config exist
  touch .ssh/config
  cp .ssh/config .ssh/config.backup
  # Disable StrictHostKeyChecking temporarily
  (echo 'Host *'; echo StrictHostKeyChecking no) >> .ssh/config
  parallel --slf my_cluster --nonall true
  # Remove the disabling of StrictHostKeyChecking
  mv .ssh/config.backup .ssh/config
@end verbatim

The servers in @strong{.parallel/my_cluster} are now added in @strong{.ssh/known_hosts}.

To run @strong{echo} on @strong{server.example.com}:

@verbatim
  seq 10 | parallel --sshlogin server.example.com echo
@end verbatim

To run commands on more than one remote computer run:

@verbatim
  seq 10 | parallel --sshlogin s1.example.com,s2.example.net echo
@end verbatim

Or:

@verbatim
  seq 10 | parallel --sshlogin server.example.com \
    --sshlogin server2.example.net echo
@end verbatim

If the login username is @emph{foo} on @emph{server2.example.net} use:

@verbatim
  seq 10 | parallel --sshlogin server.example.com \
    --sshlogin foo@server2.example.net echo
@end verbatim

If your list of hosts is @emph{server1-88.example.net} with login @emph{foo}:

@verbatim
  seq 10 | parallel -Sfoo@server{1..88}.example.net echo
@end verbatim

To distribute the commands to a list of computers, make a file
@emph{mycomputers} with all the computers:

@verbatim
  server.example.com
  foo@server2.example.com
  server3.example.com
@end verbatim

Then run:

@verbatim
  seq 10 | parallel --sshloginfile mycomputers echo
@end verbatim

To include the local computer add the special sshlogin ':' to the list:

@verbatim
  server.example.com
  foo@server2.example.com
  server3.example.com
  :
@end verbatim

GNU @strong{parallel} will try to determine the number of CPUs on each of
the remote computers, and run one job per CPU - even if the remote
computers do not have the same number of CPUs.

If the number of CPUs on the remote computers is not identified
correctly the number of CPUs can be added in front. Here the computer
has 8 CPUs.

@verbatim
  seq 10 | parallel --sshlogin 8/server.example.com echo
@end verbatim

@node EXAMPLE: Transferring of files
@chapter EXAMPLE: Transferring of files

To recompress gzipped files with @strong{bzip2} using a remote computer run:

@verbatim
  find logs/ -name '*.gz' | \
    parallel --sshlogin server.example.com \
    --transfer "zcat {} | bzip2 -9 >{.}.bz2"
@end verbatim

This will list the .gz-files in the @emph{logs} directory and all
directories below. Then it will transfer the files to
@emph{server.example.com} to the corresponding directory in
@emph{$HOME/logs}. On @emph{server.example.com} the file will be recompressed
using @strong{zcat} and @strong{bzip2} resulting in the corresponding file with
@emph{.gz} replaced with @emph{.bz2}.

If you want the resulting bz2-file to be transferred back to the local
computer add @emph{--return @{.@}.bz2}:

@verbatim
  find logs/ -name '*.gz' | \
    parallel --sshlogin server.example.com \
    --transfer --return {.}.bz2 "zcat {} | bzip2 -9 >{.}.bz2"
@end verbatim

After the recompressing is done the @emph{.bz2}-file is transferred back to
the local computer and put next to the original @emph{.gz}-file.

If you want to delete the transferred files on the remote computer add
@emph{--cleanup}. This will remove both the file transferred to the remote
computer and the files transferred from the remote computer:

@verbatim
  find logs/ -name '*.gz' | \
    parallel --sshlogin server.example.com \
    --transfer --return {.}.bz2 --cleanup "zcat {} | bzip2 -9 >{.}.bz2"
@end verbatim

If you want run on several computers add the computers to @emph{--sshlogin}
either using ',' or multiple @emph{--sshlogin}:

@verbatim
  find logs/ -name '*.gz' | \
    parallel --sshlogin server.example.com,server2.example.com \
    --sshlogin server3.example.com \
    --transfer --return {.}.bz2 --cleanup "zcat {} | bzip2 -9 >{.}.bz2"
@end verbatim

You can add the local computer using @emph{--sshlogin :}. This will disable the
removing and transferring for the local computer only:

@verbatim
  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"
@end verbatim

Often @emph{--transfer}, @emph{--return} and @emph{--cleanup} are used together. They can be
shortened to @emph{--trc}:

@verbatim
  find logs/ -name '*.gz' | \
    parallel --sshlogin server.example.com,server2.example.com \
    --sshlogin server3.example.com \
    --sshlogin : \
    --trc {.}.bz2 "zcat {} | bzip2 -9 >{.}.bz2"
@end verbatim

With the file @emph{mycomputers} containing the list of computers it becomes:

@verbatim
  find logs/ -name '*.gz' | parallel --sshloginfile mycomputers \
    --trc {.}.bz2 "zcat {} | bzip2 -9 >{.}.bz2"
@end verbatim

If the file @emph{~/.parallel/sshloginfile} contains the list of computers
the special short hand @emph{-S ..} can be used:

@verbatim
  find logs/ -name '*.gz' | parallel -S .. \
    --trc {.}.bz2 "zcat {} | bzip2 -9 >{.}.bz2"
@end verbatim

@node EXAMPLE: Distributing work to local and remote computers
@chapter EXAMPLE: Distributing work to local and remote computers

Convert *.mp3 to *.ogg running one process per CPU on local computer
and server2:

@verbatim
  parallel --trc {.}.ogg -S server2,: \
    'mpg321 -w - {} | oggenc -q0 - -o {.}.ogg' ::: *.mp3
@end verbatim

@node EXAMPLE: Running the same command on remote computers
@chapter EXAMPLE: Running the same command on remote computers

To run the command @strong{uptime} on remote computers you can do:

@verbatim
  parallel --tag --nonall -S server1,server2 uptime
@end verbatim

@strong{--nonall} reads no arguments. If you have a list of jobs you want
to run on each computer you can do:

@verbatim
  parallel --tag --onall -S server1,server2 echo ::: 1 2 3
@end verbatim

Remove @strong{--tag} if you do not want the sshlogin added before the
output.

If you have a lot of hosts use '-j0' to access more hosts in parallel.

@node EXAMPLE: Using remote computers behind NAT wall
@chapter EXAMPLE: Using remote computers behind NAT wall

If the workers are behind a NAT wall, you need some trickery to get to
them.

If you can @strong{ssh} to a jumphost, and reach the workers from there,
then the obvious solution would be this, but it @strong{does not work}:

@verbatim
  parallel --ssh 'ssh jumphost ssh' -S host1 echo ::: DOES NOT WORK
@end verbatim

It does not work because the command is dequoted by @strong{ssh} twice where
as GNU @strong{parallel} only expects it to be dequoted once.

So instead put this in @strong{~/.ssh/config}:

@verbatim
  Host host1 host2 host3
    ProxyCommand ssh jumphost.domain nc -w 1 %h 22
@end verbatim

It requires @strong{nc(netcat)} to be installed on jumphost. With this you
can simply:

@verbatim
  parallel -S host1,host2,host3 echo ::: This does work
@end verbatim

@menu
* No jumphost@comma{} but port forwards::
* No jumphost@comma{} no port forwards::
@end menu

@node No jumphost@comma{} but port forwards
@section No jumphost, but port forwards

If there is no jumphost but each server has port 22 forwarded from the
firewall (e.g. the firewall's port 22001 = port 22 on host1, 22002 = host2,
22003 = host3) then you can use @strong{~/.ssh/config}:

@verbatim
  Host host1.v
    Port 22001
  Host host2.v
    Port 22002
  Host host3.v
    Port 22003
  Host *.v
    Hostname firewall
@end verbatim

And then use host@{1..3@}.v as normal hosts:

@verbatim
  parallel -S host1.v,host2.v,host3.v echo ::: a b c
@end verbatim

@node No jumphost@comma{} no port forwards
@section No jumphost, no port forwards

If ports cannot be forwarded, you need some sort of VPN to traverse
the NAT-wall. TOR is one options for that, as it is very easy to get
working.

You need to install TOR and setup a hidden service. In @strong{torrc} put:

@verbatim
  HiddenServiceDir /var/lib/tor/hidden_service/
  HiddenServicePort 22 127.0.0.1:22
@end verbatim

Then start TOR: @strong{/etc/init.d/tor restart}

The TOR hostname is now in @strong{/var/lib/tor/hidden_service/hostname} and
is something similar to @strong{izjafdceobowklhz.onion}. Now you simply
prepend @strong{torsocks} to @strong{ssh}:

@verbatim
  parallel --ssh 'torsocks ssh' -S izjafdceobowklhz.onion \
    -S zfcdaeiojoklbwhz.onion,auclucjzobowklhi.onion echo ::: a b c
@end verbatim

If not all hosts are accessible through TOR:

@verbatim
  parallel -S 'torsocks ssh izjafdceobowklhz.onion,host2,host3' \
    echo ::: a b c
@end verbatim

See more @strong{ssh} tricks on https://en.wikibooks.org/wiki/OpenSSH/Cookbook/Proxies_and_Jump_Hosts

@node EXAMPLE: Parallelizing rsync
@chapter EXAMPLE: Parallelizing rsync

@strong{rsync} is a great tool, but sometimes it will not fill up the
available bandwidth. This is often a problem when copying several big
files over high speed connections.

The following will start one @strong{rsync} per big file in @emph{src-dir} to
@emph{dest-dir} on the server @emph{fooserver}:

@verbatim
  cd src-dir; find . -type f -size +100000 | \
    parallel -v ssh fooserver mkdir -p /dest-dir/{//}\; \
      rsync -s -Havessh {} fooserver:/dest-dir/{}
@end verbatim

The dirs created may end up with wrong permissions and smaller files
are not being transferred. To fix those run @strong{rsync} a final time:

@verbatim
  rsync -Havessh src-dir/ fooserver:/dest-dir/
@end verbatim

If you are unable to push data, but need to pull them and the files
are called digits.png (e.g. 000000.png) you might be able to do:

@verbatim
  seq -w 0 99 | parallel rsync -Havessh fooserver:src/*{}.png destdir/
@end verbatim

@node EXAMPLE: Use multiple inputs in one command
@chapter EXAMPLE: Use multiple inputs in one command

Copy files like foo.es.ext to foo.ext:

@verbatim
  ls *.es.* | perl -pe 'print; s/\.es//' | parallel -N2 cp {1} {2}
@end verbatim

The perl command spits out 2 lines for each input. GNU @strong{parallel}
takes 2 inputs (using @strong{-N2}) and replaces @{1@} and @{2@} with the inputs.

Count in binary:

@verbatim
  parallel -k echo ::: 0 1 ::: 0 1 ::: 0 1 ::: 0 1 ::: 0 1 ::: 0 1
@end verbatim

Print the number on the opposing sides of a six sided die:

@verbatim
  parallel --link -a <(seq 6) -a <(seq 6 -1 1) echo
  parallel --link echo :::: <(seq 6) <(seq 6 -1 1)
@end verbatim

Convert files from all subdirs to PNG-files with consecutive numbers
(useful for making input PNG's for @strong{ffmpeg}):

@verbatim
  parallel --link -a <(find . -type f | sort) \
    -a <(seq $(find . -type f|wc -l)) convert {1} {2}.png
@end verbatim

Alternative version:

@verbatim
  find . -type f | sort | parallel convert {} {#}.png
@end verbatim

@node EXAMPLE: Use a table as input
@chapter EXAMPLE: Use a table as input

Content of table_file.tsv:

@verbatim
  foo<TAB>bar
  baz <TAB> quux
@end verbatim

To run:

@verbatim
  cmd -o bar -i foo
  cmd -o quux -i baz
@end verbatim

you can run:

@verbatim
  parallel -a table_file.tsv --colsep '\t' cmd -o {2} -i {1}
@end verbatim

Note: The default for GNU @strong{parallel} is to remove the spaces around
the columns. To keep the spaces:

@verbatim
  parallel -a table_file.tsv --trim n --colsep '\t' cmd -o {2} -i {1}
@end verbatim

@node EXAMPLE: Output to database
@chapter EXAMPLE: Output to database

GNU @strong{parallel} can output to a database table and a CSV-file:

@verbatim
  DBURL=csv:///%2Ftmp%2Fmy.csv
  DBTABLEURL=$DBURL/mytable
  parallel --sqlandworker $DBTABLEURL seq ::: {1..10}
@end verbatim

It is rather slow and takes up a lot of CPU time because GNU
@strong{parallel} parses the whole CSV file for each update.

A better approach is to use an SQLite-base and then convert that to CSV:

@verbatim
  DBURL=sqlite3:///%2Ftmp%2Fmy.sqlite
  DBTABLEURL=$DBURL/mytable
  parallel --sqlandworker $DBTABLEURL seq ::: {1..10}
  sql $DBURL '.headers on' '.mode csv' 'SELECT * FROM mytable;'
@end verbatim

This takes around a second per job.

If you have access to a real database system, such as PostgreSQL, it
is even faster:

@verbatim
  DBURL=pg://user:pass@host/mydb
  DBTABLEURL=$DBURL/mytable
  parallel --sqlandworker $DBTABLEURL seq ::: {1..10}
  sql $DBURL \
    "COPY (SELECT * FROM mytable) TO stdout DELIMITER ',' CSV HEADER;"
@end verbatim

Or MySQL:

@verbatim
  DBURL=mysql://user:pass@host/mydb
  DBTABLEURL=$DBURL/mytable
  parallel --sqlandworker $DBTABLEURL seq ::: {1..10}
  sql -p -B $DBURL "SELECT * FROM mytable;" > mytable.tsv
  perl -pe 's/"/""/g; s/\t/","/g; s/^/"/; s/$/"/; s/\\\\/\\/g;
    s/\\t/\t/g; s/\\n/\n/g;' mytable.tsv
@end verbatim

@node EXAMPLE: Output to CSV-file for R
@chapter EXAMPLE: Output to CSV-file for R

If you have no need for the advanced job distribution control that a
database provides, but you simply want output into a CSV file that you
can read into R or LibreCalc, then you can use @strong{--results}:

@verbatim
  parallel --results my.csv seq ::: 10 20 30
  R
  > mydf <- read.csv("my.csv");
  > print(mydf[2,])
  > write(as.character(mydf[2,c("Stdout")]),'')
@end verbatim

@node EXAMPLE: Use XML as input
@chapter EXAMPLE: Use XML as input

The show Aflyttet on Radio 24syv publishes an RSS feed with their audio
podcasts on: http://arkiv.radio24syv.dk/audiopodcast/channel/4466232

Using @strong{xpath} you can extract the URLs for 2019 and download them
using GNU @strong{parallel}:

@verbatim
  wget -O - http://arkiv.radio24syv.dk/audiopodcast/channel/4466232 | \
    xpath -e "//pubDate[contains(text(),'2019')]/../enclosure/@url" | \
    parallel -u wget '{= s/ url="//; s/"//; =}'
@end verbatim

@node EXAMPLE: Run the same command 10 times
@chapter EXAMPLE: Run the same command 10 times

If you want to run the same command with the same arguments 10 times
in parallel you can do:

@verbatim
  seq 10 | parallel -n0 my_command my_args
@end verbatim

@node EXAMPLE: Working as cat | sh. Resource inexpensive jobs and evaluation
@chapter EXAMPLE: Working as cat | sh. Resource inexpensive jobs and evaluation

GNU @strong{parallel} can work similar to @strong{cat | sh}.

A resource inexpensive job is a job that takes very little CPU, disk
I/O and network I/O. Ping is an example of a resource inexpensive
job. wget is too - if the webpages are small.

The content of the file jobs_to_run:

@verbatim
  ping -c 1 10.0.0.1
  wget http://example.com/status.cgi?ip=10.0.0.1
  ping -c 1 10.0.0.2
  wget http://example.com/status.cgi?ip=10.0.0.2
  ...
  ping -c 1 10.0.0.255
  wget http://example.com/status.cgi?ip=10.0.0.255
@end verbatim

To run 100 processes simultaneously do:

@verbatim
  parallel -j 100 < jobs_to_run
@end verbatim

As there is not a @emph{command} the jobs will be evaluated by the shell.

@node EXAMPLE: Processing a big file using more CPUs
@chapter EXAMPLE: Processing a big file using more CPUs

To process a big file or some output you can use @strong{--pipe} to split up
the data into blocks and pipe the blocks into the processing program.

If the program is @strong{gzip -9} you can do:

@verbatim
  cat bigfile | parallel --pipe --recend '' -k gzip -9 > bigfile.gz
@end verbatim

This will split @strong{bigfile} into blocks of 1 MB and pass that to @strong{gzip
-9} in parallel. One @strong{gzip} will be run per CPU. The output of @strong{gzip
-9} will be kept in order and saved to @strong{bigfile.gz}

@strong{gzip} works fine if the output is appended, but some processing does
not work like that - for example sorting. For this GNU @strong{parallel} can
put the output of each command into a file. This will sort a big file
in parallel:

@verbatim
  cat bigfile | parallel --pipe --files sort |\
    parallel -Xj1 sort -m {} ';' rm {} >bigfile.sort
@end verbatim

Here @strong{bigfile} is split into blocks of around 1MB, each block ending
in '\n' (which is the default for @strong{--recend}). Each block is passed
to @strong{sort} and the output from @strong{sort} is saved into files. These
files are passed to the second @strong{parallel} that runs @strong{sort -m} on the
files before it removes the files. The output is saved to
@strong{bigfile.sort}.

GNU @strong{parallel}'s @strong{--pipe} maxes out at around 100 MB/s because every
byte has to be copied through GNU @strong{parallel}. But if @strong{bigfile} is a
real (seekable) file GNU @strong{parallel} can by-pass the copying and send
the parts directly to the program:

@verbatim
  parallel --pipepart --block 100m -a bigfile --files sort |\
    parallel -Xj1 sort -m {} ';' rm {} >bigfile.sort
@end verbatim

@node EXAMPLE: Grouping input lines
@chapter EXAMPLE: Grouping input lines

When processing with @strong{--pipe} you may have lines grouped by a
value. Here is @emph{my.csv}:

@verbatim
   Transaction Customer Item
        1       a       53
        2       b       65
        3       b       82
        4       c       96
        5       c       67
        6       c       13
        7       d       90
        8       d       43
        9       d       91
        10      d       84
        11      e       72
        12      e       102
        13      e       63
        14      e       56
        15      e       74
@end verbatim

Let us assume you want GNU @strong{parallel} to process each customer. In
other words: You want all the transactions for a single customer to be
treated as a single record.

To do this we preprocess the data with a program that inserts a record
separator before each customer (column 2 = $F[1]). Here we first make
a 50 character random string, which we then use as the separator:

@verbatim
  sep=`perl -e 'print map { ("a".."z","A".."Z")[rand(52)] } (1..50);'`
  cat my.csv | \
     perl -ape '$F[1] ne $l and print "'$sep'"; $l = $F[1]' | \
     parallel --recend $sep --rrs --pipe -N1 wc
@end verbatim

If your program can process multiple customers replace @strong{-N1} with a
reasonable @strong{--blocksize}.

@node EXAMPLE: Running more than 250 jobs workaround
@chapter EXAMPLE: Running more than 250 jobs workaround

If you need to run a massive amount of jobs in parallel, then you will
likely hit the filehandle limit which is often around 250 jobs. If you
are super user you can raise the limit in /etc/security/limits.conf
but you can also use this workaround. The filehandle limit is per
process. That means that if you just spawn more GNU @strong{parallel}s then
each of them can run 250 jobs. This will spawn up to 2500 jobs:

@verbatim
  cat myinput |\
    parallel --pipe -N 50 --roundrobin -j50 parallel -j50 your_prg
@end verbatim

This will spawn up to 62500 jobs (use with caution - you need 64 GB
RAM to do this, and you may need to increase /proc/sys/kernel/pid_max):

@verbatim
  cat myinput |\
    parallel --pipe -N 250 --roundrobin -j250 parallel -j250 your_prg
@end verbatim

@node EXAMPLE: Working as mutex and counting semaphore
@chapter EXAMPLE: Working as mutex and counting semaphore

The command @strong{sem} is an alias for @strong{parallel --semaphore}.

A counting semaphore will allow a given number of jobs to be started
in the background.  When the number of jobs are running in the
background, GNU @strong{sem} will wait for one of these to complete before
starting another command. @strong{sem --wait} will wait for all jobs to
complete.

Run 10 jobs concurrently in the background:

@verbatim
  for i in *.log ; do
    echo $i
    sem -j10 gzip $i ";" echo done
  done
  sem --wait
@end verbatim

A mutex is a counting semaphore allowing only one job to run. This
will edit the file @emph{myfile} and prepends the file with lines with the
numbers 1 to 3.

@verbatim
  seq 3 | parallel sem sed -i -e '1i{}' myfile
@end verbatim

As @emph{myfile} can be very big it is important only one process edits
the file at the same time.

Name the semaphore to have multiple different semaphores active at the
same time:

@verbatim
  seq 3 | parallel sem --id mymutex sed -i -e '1i{}' myfile
@end verbatim

@node EXAMPLE: Mutex for a script
@chapter EXAMPLE: Mutex for a script

Assume a script is called from cron or from a web service, but only
one instance can be run at a time. With @strong{sem} and @strong{--shebang-wrap}
the script can be made to wait for other instances to finish. Here in
@strong{bash}:

@verbatim
  #!/usr/bin/sem --shebang-wrap -u --id $0 --fg /bin/bash
  
  echo This will run
  sleep 5
  echo exclusively
@end verbatim

Here @strong{perl}:

@verbatim
  #!/usr/bin/sem --shebang-wrap -u --id $0 --fg /usr/bin/perl
  
  print "This will run ";
  sleep 5;
  print "exclusively\n";
@end verbatim

Here @strong{python}:

@verbatim
  #!/usr/local/bin/sem --shebang-wrap -u --id $0 --fg /usr/bin/python
  
  import time
  print "This will run ";
  time.sleep(5)
  print "exclusively";
@end verbatim

@node EXAMPLE: Start editor with filenames from stdin (standard input)
@chapter EXAMPLE: Start editor with filenames from stdin (standard input)

You can use GNU @strong{parallel} to start interactive programs like emacs or vi:

@verbatim
  cat filelist | parallel --tty -X emacs
  cat filelist | parallel --tty -X vi
@end verbatim

If there are more files than will fit on a single command line, the
editor will be started again with the remaining files.

@node EXAMPLE: Running sudo
@chapter EXAMPLE: Running sudo

@strong{sudo} requires a password to run a command as root. It caches the
access, so you only need to enter the password again if you have not
used @strong{sudo} for a while.

The command:

@verbatim
  parallel sudo echo ::: This is a bad idea
@end verbatim

is no good, as you would be prompted for the sudo password for each of
the jobs. You can either do:

@verbatim
  sudo echo This
  parallel sudo echo ::: is a good idea
@end verbatim

or:

@verbatim
  sudo parallel echo ::: This is a good idea
@end verbatim

This way you only have to enter the sudo password once.

@node EXAMPLE: GNU Parallel as queue system/batch manager
@chapter EXAMPLE: GNU Parallel as queue system/batch manager

GNU @strong{parallel} can work as a simple job queue system or batch manager.
The idea is to put the jobs into a file and have GNU @strong{parallel} read
from that continuously. As GNU @strong{parallel} will stop at end of file we
use @strong{tail} to continue reading:

@verbatim
  true >jobqueue; tail -n+0 -f jobqueue | parallel
@end verbatim

To submit your jobs to the queue:

@verbatim
  echo my_command my_arg >> jobqueue
@end verbatim

You can of course use @strong{-S} to distribute the jobs to remote
computers:

@verbatim
  true >jobqueue; tail -n+0 -f jobqueue | parallel -S ..
@end verbatim

If you keep this running for a long time, jobqueue will grow. A way of
removing the jobs already run is by making GNU @strong{parallel} stop when
it hits a special value and then restart. To use @strong{--eof} to make GNU
@strong{parallel} exit, @strong{tail} also needs to be forced to exit:

@verbatim
  true >jobqueue;
  while true; do
    tail -n+0 -f jobqueue |
      (parallel -E StOpHeRe -S ..; echo GNU Parallel is now done;
       perl -e 'while(<>){/StOpHeRe/ and last};print <>' jobqueue > j2;
       (seq 1000 >> jobqueue &);
       echo Done appending dummy data forcing tail to exit)
    echo tail exited;
    mv j2 jobqueue
  done
@end verbatim

In some cases you can run on more CPUs and computers during the night:

@verbatim
  # Day time
  echo 50% > jobfile
  cp day_server_list ~/.parallel/sshloginfile
  # Night time
  echo 100% > jobfile
  cp night_server_list ~/.parallel/sshloginfile
  tail -n+0 -f jobqueue | parallel --jobs jobfile -S ..
@end verbatim

GNU Parallel discovers if @strong{jobfile} or @strong{~/.parallel/sshloginfile}
changes.

There is a a small issue when using GNU @strong{parallel} as queue
system/batch manager: You have to submit JobSlot number of jobs before
they will start, and after that you can submit one at a time, and job
will start immediately if free slots are available.  Output from the
running or completed jobs are held back and will only be printed when
JobSlots more jobs has been started (unless you use --ungroup or
--line-buffer, in which case the output from the jobs are printed
immediately).  E.g. if you have 10 jobslots then the output from the
first completed job will only be printed when job 11 has started, and
the output of second completed job will only be printed when job 12
has started.

@node EXAMPLE: GNU Parallel as dir processor
@chapter EXAMPLE: GNU Parallel as dir processor

If you have a dir in which users drop files that needs to be processed
you can do this on GNU/Linux (If you know what @strong{inotifywait} is
called on other platforms file a bug report):

@verbatim
  inotifywait -qmre MOVED_TO -e CLOSE_WRITE --format %w%f my_dir |\
    parallel -u echo
@end verbatim

This will run the command @strong{echo} on each file put into @strong{my_dir} or
subdirs of @strong{my_dir}.

You can of course use @strong{-S} to distribute the jobs to remote
computers:

@verbatim
  inotifywait -qmre MOVED_TO -e CLOSE_WRITE --format %w%f my_dir |\
    parallel -S ..  -u echo
@end verbatim

If the files to be processed are in a tar file then unpacking one file
and processing it immediately may be faster than first unpacking all
files. Set up the dir processor as above and unpack into the dir.

Using GNU Parallel as dir processor has the same limitations as using
GNU Parallel as queue system/batch manager.

@node EXAMPLE: Locate the missing package
@chapter EXAMPLE: Locate the missing package

If you have downloaded source and tried compiling it, you may have seen:

@verbatim
  $ ./configure
  [...]
  checking for something.h... no
  configure: error: "libsomething not found"
@end verbatim

Often it is not obvious which package you should install to get that
file. Debian has `apt-file` to search for a file. `tracefile` from
https://gitlab.com/ole.tange/tangetools can tell which files a program
tried to access. In this case we are interested in one of the last
files:

@verbatim
  $ tracefile -un ./configure | tail | parallel -j0 apt-file search
@end verbatim

@node QUOTING
@chapter QUOTING

GNU @strong{parallel} is very liberal in quoting. You only need to quote
characters that have special meaning in shell:

@verbatim
  ( ) $ ` ' " < > ; | \
@end verbatim

and depending on context these needs to be quoted, too:

@verbatim
  ~ & # ! ? space * {
@end verbatim

Therefore most people will never need more quoting than putting '\'
in front of the special characters.

Often you can simply put \' around every ':

@verbatim
  perl -ne '/^\S+\s+\S+$/ and print $ARGV,"\n"' file
@end verbatim

can be quoted:

@verbatim
  parallel perl -ne \''/^\S+\s+\S+$/ and print $ARGV,"\n"'\' ::: file
@end verbatim

However, when you want to use a shell variable you need to quote the
$-sign. Here is an example using $PARALLEL_SEQ. This variable is set
by GNU @strong{parallel} itself, so the evaluation of the $ must be done by
the sub shell started by GNU @strong{parallel}:

@verbatim
  seq 10 | parallel -N2 echo seq:\$PARALLEL_SEQ arg1:{1} arg2:{2}
@end verbatim

If the variable is set before GNU @strong{parallel} starts you can do this:

@verbatim
  VAR=this_is_set_before_starting
  echo test | parallel echo {} $VAR
@end verbatim

Prints: @strong{test this_is_set_before_starting}

It is a little more tricky if the variable contains more than one space in a row:

@verbatim
  VAR="two  spaces  between  each  word"
  echo test | parallel echo {} \'"$VAR"\'
@end verbatim

Prints: @strong{test two  spaces  between  each  word}

If the variable should not be evaluated by the shell starting GNU
@strong{parallel} but be evaluated by the sub shell started by GNU
@strong{parallel}, then you need to quote it:

@verbatim
  echo test | parallel VAR=this_is_set_after_starting \; echo {} \$VAR
@end verbatim

Prints: @strong{test this_is_set_after_starting}

It is a little more tricky if the variable contains space:

@verbatim
  echo test |\
    parallel VAR='"two  spaces  between  each  word"' echo {} \'"$VAR"\'
@end verbatim

Prints: @strong{test two  spaces  between  each  word}

$$ is the shell variable containing the process id of the shell. This
will print the process id of the shell running GNU @strong{parallel}:

@verbatim
  seq 10 | parallel echo $$
@end verbatim

And this will print the process ids of the sub shells started by GNU
@strong{parallel}.

@verbatim
  seq 10 | parallel echo \$\$
@end verbatim

If the special characters should not be evaluated by the sub shell
then you need to protect it against evaluation from both the shell
starting GNU @strong{parallel} and the sub shell:

@verbatim
  echo test | parallel echo {} \\\$VAR
@end verbatim

Prints: @strong{test $VAR}

GNU @strong{parallel} can protect against evaluation by the sub shell by
using -q:

@verbatim
  echo test | parallel -q echo {} \$VAR
@end verbatim

Prints: @strong{test $VAR}

This is particularly useful if you have lots of quoting. If you want
to run a perl script like this:

@verbatim
  perl -ne '/^\S+\s+\S+$/ and print $ARGV,"\n"' file
@end verbatim

It needs to be quoted like one of these:

@verbatim
  ls | parallel perl -ne '/^\\S+\\s+\\S+\$/\ and\ print\ \$ARGV,\"\\n\"'
  ls | parallel perl -ne \''/^\S+\s+\S+$/ and print $ARGV,"\n"'\'
@end verbatim

Notice how spaces, \'s, "'s, and $'s need to be quoted. GNU @strong{parallel}
can do the quoting by using option -q:

@verbatim
  ls | parallel -q  perl -ne '/^\S+\s+\S+$/ and print $ARGV,"\n"'
@end verbatim

However, this means you cannot make the sub shell interpret special
characters. For example because of @strong{-q} this WILL NOT WORK:

@verbatim
  ls *.gz | parallel -q "zcat {} >{.}"
  ls *.gz | parallel -q "zcat {} | bzip2 >{.}.bz2"
@end verbatim

because > and | need to be interpreted by the sub shell.

If you get errors like:

@verbatim
  sh: -c: line 0: syntax error near unexpected token
  sh: Syntax error: Unterminated quoted string
  sh: -c: line 0: unexpected EOF while looking for matching `''
  sh: -c: line 1: syntax error: unexpected end of file
  zsh:1: no matches found:
@end verbatim

then you might try using @strong{-q}.

If you are using @strong{bash} process substitution like @strong{<(cat foo)} then
you may try @strong{-q} and prepending @emph{command} with @strong{bash -c}:

@verbatim
  ls | parallel -q bash -c 'wc -c <(echo {})'
@end verbatim

Or for substituting output:

@verbatim
  ls | parallel -q bash -c \
    'tar c {} | tee >(gzip >{}.tar.gz) | bzip2 >{}.tar.bz2'
@end verbatim

@strong{Conclusion}: To avoid dealing with the quoting problems it may be
easier just to write a small script or a function (remember to
@strong{export -f} the function) and have GNU @strong{parallel} call that.

@node LIST RUNNING JOBS
@chapter LIST RUNNING JOBS

If you want a list of the jobs currently running you can run:

@verbatim
  killall -USR1 parallel
@end verbatim

GNU @strong{parallel} will then print the currently running jobs on stderr
(standard error).

@node COMPLETE RUNNING JOBS BUT DO NOT START NEW JOBS
@chapter COMPLETE RUNNING JOBS BUT DO NOT START NEW JOBS

If you regret starting a lot of jobs you can simply break GNU @strong{parallel},
but if you want to make sure you do not have half-completed jobs you
should send the signal @strong{SIGHUP} to GNU @strong{parallel}:

@verbatim
  killall -HUP parallel
@end verbatim

This will tell GNU @strong{parallel} to not start any new jobs, but wait until
the currently running jobs are finished before exiting.

@node ENVIRONMENT VARIABLES
@chapter ENVIRONMENT VARIABLES

@table @asis
@item $PARALLEL_HOME
@anchor{$PARALLEL_HOME}

Dir where GNU @strong{parallel} stores config files, semaphores, and caches
information between invocations. Default: $HOME/.parallel.

@item $PARALLEL_PID
@anchor{$PARALLEL_PID}

The environment variable $PARALLEL_PID is set by GNU @strong{parallel} and
is visible to the jobs started from GNU @strong{parallel}. This makes it
possible for the jobs to communicate directly to GNU @strong{parallel}.
Remember to quote the $, so it gets evaluated by the correct
shell.

@strong{Example:} If each of the jobs tests a solution and one of jobs finds
the solution the job can tell GNU @strong{parallel} not to start more jobs
by: @strong{kill -HUP $PARALLEL_PID}. This only works on the local
computer.

@item $PARALLEL_RSYNC_OPTS
@anchor{$PARALLEL_RSYNC_OPTS}

Options to pass on to @strong{rsync}. Defaults to: -rlDzR.

@item $PARALLEL_SHELL
@anchor{$PARALLEL_SHELL}

Use this shell for the commands run by GNU Parallel:

@itemize
@item $PARALLEL_SHELL. If undefined use:

@item The shell that started GNU Parallel. If that cannot be determined:

@item $SHELL. If undefined use:

@item /bin/sh

@end itemize

@item $PARALLEL_SSH
@anchor{$PARALLEL_SSH}

GNU @strong{parallel} defaults to using @strong{ssh} for remote access. This can
be overridden with $PARALLEL_SSH, which again can be overridden with
@strong{--ssh}. It can also be set on a per server basis (see
@strong{--sshlogin}).

@item $PARALLEL_SEQ
@anchor{$PARALLEL_SEQ}

$PARALLEL_SEQ will be set to the sequence number of the job
running. Remember to quote the $, so it gets evaluated by the correct
shell.

@strong{Example:}

@verbatim
  seq 10 | parallel -N2 \
    echo seq:'$'PARALLEL_SEQ arg1:{1} arg2:{2}
@end verbatim

@item $PARALLEL_TMUX
@anchor{$PARALLEL_TMUX}

Path to @strong{tmux}. If unset the @strong{tmux} in $PATH is used.

@item $TMPDIR
@anchor{$TMPDIR}

Directory for temporary files. See: @strong{--tmpdir}.

@item $PARALLEL
@anchor{$PARALLEL}

The environment variable $PARALLEL will be used as default options for
GNU @strong{parallel}. If the variable contains special shell characters
(e.g. $, *, or space) then these need to be to be escaped with \.

@strong{Example:}

@verbatim
  cat list | parallel -j1 -k -v ls
  cat list | parallel -j1 -k -v -S"myssh user@server" ls
@end verbatim

can be written as:

@verbatim
  cat list | PARALLEL="-kvj1" parallel ls
  cat list | PARALLEL='-kvj1 -S myssh\ user@server' \
    parallel echo
@end verbatim

Notice the \ in the middle is needed because 'myssh' and 'user@@server'
must be one argument.

@end table

@node DEFAULT PROFILE (CONFIG FILE)
@chapter DEFAULT PROFILE (CONFIG FILE)

The global configuration file /etc/parallel/config, followed by user
configuration file ~/.parallel/config (formerly known as .parallelrc)
will be read in turn if they exist.  Lines starting with '#' will be
ignored. The format can follow that of the environment variable
$PARALLEL, but it is often easier to simply put each option on its own
line.

Options on the command line take precedence, followed by the
environment variable $PARALLEL, user configuration file
~/.parallel/config, and finally the global configuration file
/etc/parallel/config.

Note that no file that is read for options, nor the environment
variable $PARALLEL, may contain retired options such as @strong{--tollef}.

@node PROFILE FILES
@chapter PROFILE FILES

If @strong{--profile} set, GNU @strong{parallel} will read the profile from that
file rather than the global or user configuration files. You can have
multiple @strong{--profiles}.

Example: Profile for running a command on every sshlogin in
~/.ssh/sshlogins and prepend the output with the sshlogin:

@verbatim
  echo --tag -S .. --nonall > ~/.parallel/n
  parallel -Jn uptime
@end verbatim

Example: Profile for running every command with @strong{-j-1} and @strong{nice}

@verbatim
  echo -j-1 nice > ~/.parallel/nice_profile
  parallel -J nice_profile bzip2 -9 ::: *
@end verbatim

Example: Profile for running a perl script before every command:

@verbatim
  echo "perl -e '\$a=\$\$; print \$a,\" \",'\$PARALLEL_SEQ',\" \";';" \
    > ~/.parallel/pre_perl
  parallel -J pre_perl echo ::: *
@end verbatim

Note how the $ and " need to be quoted using \.

Example: Profile for running distributed jobs with @strong{nice} on the
remote computers:

@verbatim
  echo -S .. nice > ~/.parallel/dist
  parallel -J dist --trc {.}.bz2 bzip2 -9 ::: *
@end verbatim

@node EXIT STATUS
@chapter EXIT STATUS

Exit status depends on @strong{--halt-on-error} if one of these is used:
success=X, success=Y%, fail=Y%.

@table @asis
@item 0
@anchor{0 2}

All jobs ran without error. If success=X is used: X jobs ran without
error. If success=Y% is used: Y% of the jobs ran without error.

@item 1-100
@anchor{1-100}

Some of the jobs failed. The exit status gives the number of failed
jobs. If Y% is used the exit status is the percentage of jobs that
failed.

@item 101
@anchor{101}

More than 100 jobs failed.

@item 255
@anchor{255}

Other error.

@item -1 (In joblog and SQL table)
@anchor{-1 (In joblog and SQL table)}

Killed by Ctrl-C, timeout, not enough memory or similar.

@item -2 (In joblog and SQL table)
@anchor{-2 (In joblog and SQL table)}

skip() was called in @strong{@{= =@}}.

@item -1000 (In SQL table)
@anchor{-1000 (In SQL table)}

Job is ready to run (set by --sqlmaster).

@item -1220 (In SQL table)
@anchor{-1220 (In SQL table)}

Job is taken by worker (set by --sqlworker).

@end table

If fail=1 is used, the exit status will be the exit status of the
failing job.

@node DIFFERENCES BETWEEN GNU Parallel AND ALTERNATIVES
@chapter DIFFERENCES BETWEEN GNU Parallel AND ALTERNATIVES

See: @strong{man parallel_alternatives}

@node BUGS
@chapter BUGS

@menu
* Quoting of newline::
* Speed::
* --nice limits command length::
* Aliases and functions do not work::
* Database with MySQL fails randomly::
@end menu

@node Quoting of newline
@section Quoting of newline

Because of the way newline is quoted this will not work:

@verbatim
  echo 1,2,3 | parallel -vkd, "echo 'a{}b'"
@end verbatim

However, these will all work:

@verbatim
  echo 1,2,3 | parallel -vkd, echo a{}b
  echo 1,2,3 | parallel -vkd, "echo 'a'{}'b'"
  echo 1,2,3 | parallel -vkd, "echo 'a'"{}"'b'"
@end verbatim

@node Speed
@section Speed

@menu
* Startup::
* Job startup::
* SSH::
* Disk access::
@end menu

@node Startup
@subsection Startup

GNU @strong{parallel} is slow at starting up - around 250 ms the first time
and 150 ms after that.

@node Job startup
@subsection Job startup

Starting a job on the local machine takes around 10 ms. This can be a
big overhead if the job takes very few ms to run. Often you can group
small jobs together using @strong{-X} which will make the overhead less
significant. Or you can run multiple GNU @strong{parallel}s as described in
@strong{EXAMPLE: Speeding up fast jobs}.

@node SSH
@subsection SSH

When using multiple computers GNU @strong{parallel} opens @strong{ssh} connections
to them to figure out how many connections can be used reliably
simultaneously (Namely SSHD's MaxStartups). This test is done for each
host in serial, so if your @strong{--sshloginfile} contains many hosts it may
be slow.

If your jobs are short you may see that there are fewer jobs running
on the remote systems than expected. This is due to time spent logging
in and out. @strong{-M} may help here.

@node Disk access
@subsection Disk access

A single disk can normally read data faster if it reads one file at a
time instead of reading a lot of files in parallel, as this will avoid
disk seeks. However, newer disk systems with multiple drives can read
faster if reading from multiple files in parallel.

If the jobs are of the form read-all-compute-all-write-all, so
everything is read before anything is written, it may be faster to
force only one disk access at the time:

@verbatim
  sem --id diskio cat file | compute | sem --id diskio cat > file
@end verbatim

If the jobs are of the form read-compute-write, so writing starts
before all reading is done, it may be faster to force only one reader
and writer at the time:

@verbatim
  sem --id read cat file | compute | sem --id write cat > file
@end verbatim

If the jobs are of the form read-compute-read-compute, it may be
faster to run more jobs in parallel than the system has CPUs, as some
of the jobs will be stuck waiting for disk access.

@node --nice limits command length
@section --nice limits command length

The current implementation of @strong{--nice} is too pessimistic in the max
allowed command length. It only uses a little more than half of what
it could. This affects @strong{-X} and @strong{-m}. If this becomes a real problem for
you, file a bug-report.

@node Aliases and functions do not work
@section Aliases and functions do not work

If you get:

@verbatim
  Can't exec "command": No such file or directory
@end verbatim

or:

@verbatim
  open3: exec of by command failed
@end verbatim

or:

@verbatim
  /bin/bash: command: command not found
@end verbatim

it may be because @emph{command} is not known, but it could also be
because @emph{command} is an alias or a function. If it is a function you
need to @strong{export -f} the function first or use @strong{env_parallel}. An
alias will only work if you use @strong{env_parallel}.

@node Database with MySQL fails randomly
@section Database with MySQL fails randomly

The @strong{--sql*} options may fail randomly with MySQL. This problem does
not exist with PostgreSQL.

@node REPORTING BUGS
@chapter REPORTING BUGS

Report bugs to <bug-parallel@@gnu.org> or
https://savannah.gnu.org/bugs/?func=additem&group=parallel

See a perfect bug report on
https://lists.gnu.org/archive/html/bug-parallel/2015-01/msg00000.html

Your bug report should always include:

@itemize
@item The error message you get (if any). If the error message is not from
GNU @strong{parallel} you need to show why you think GNU @strong{parallel} caused
these.

@item The complete output of @strong{parallel --version}. If you are not running
the latest released version (see http://ftp.gnu.org/gnu/parallel/) you
should specify why you believe the problem is not fixed in that
version.

@item A minimal, complete, and verifiable example (See description on
http://stackoverflow.com/help/mcve).

It should be a complete example that others can run that shows the problem
including all files needed to run the example. This should preferably
be small and simple, so try to remove as many options as possible. A
combination of @strong{yes}, @strong{seq}, @strong{cat}, @strong{echo}, and @strong{sleep} can
reproduce most errors. If your example requires large files, see if
you can make them by something like @strong{seq 1000000} > @strong{file} or @strong{yes
| head -n 10000000} > @strong{file}.

If your example requires remote execution, see if you can use
@strong{localhost} - maybe using another login.

If you have access to a different system, test if the MCVE shows the
problem on that system.

@item The output of your example. If your problem is not easily reproduced
by others, the output might help them figure out the problem.

@item Whether you have watched the intro videos
(http://www.youtube.com/playlist?list=PL284C9FF2488BC6D1), walked
through the tutorial (man parallel_tutorial), and read the EXAMPLE
section in the man page (man parallel - search for EXAMPLE:).

@end itemize

If you suspect the error is dependent on your environment or
distribution, please see if you can reproduce the error on one of
these VirtualBox images:
http://sourceforge.net/projects/virtualboximage/files/
http://www.osboxes.org/virtualbox-images/

Specifying the name of your distribution is not enough as you may have
installed software that is not in the VirtualBox images.

If you cannot reproduce the error on any of the VirtualBox images
above, see if you can build a VirtualBox image on which you can
reproduce the error. If not you should assume the debugging will be
done through you. That will put more burden on you and it is extra
important you give any information that help. In general the problem
will be fixed faster and with less work for you if you can reproduce
the error on a VirtualBox.

@node AUTHOR
@chapter AUTHOR

When using GNU @strong{parallel} for a publication please cite:

O. Tange (2011): GNU Parallel - The Command-Line Power Tool, ;login:
The USENIX Magazine, February 2011:42-47.

This helps funding further development; and it won't cost you a cent.
If you pay 10000 EUR you should feel free to use GNU Parallel without citing.

Copyright (C) 2007-10-18 Ole Tange, http://ole.tange.dk

Copyright (C) 2008-2010 Ole Tange, http://ole.tange.dk

Copyright (C) 2010-2019 Ole Tange,
http://ole.tange.dk and Free Software Foundation, Inc.

Parts of the manual concerning @strong{xargs} compatibility is inspired by
the manual of @strong{xargs} from GNU findutils 4.4.2.

@node LICENSE
@chapter LICENSE

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/>.

@menu
* Documentation license I::
* Documentation license II::
@end menu

@node Documentation license I
@section Documentation license I

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.

@node Documentation license II
@section Documentation license II

You are free:

@table @asis
@item @strong{to Share}
@anchor{@strong{to Share}}

to copy, distribute and transmit the work

@item @strong{to Remix}
@anchor{@strong{to Remix}}

to adapt the work

@end table

Under the following conditions:

@table @asis
@item @strong{Attribution}
@anchor{@strong{Attribution}}

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).

@item @strong{Share Alike}
@anchor{@strong{Share Alike}}

If you alter, transform, or build upon this work, you may distribute
the resulting work only under the same, similar or a compatible
license.

@end table

With the understanding that:

@table @asis
@item @strong{Waiver}
@anchor{@strong{Waiver}}

Any of the above conditions can be waived if you get permission from
the copyright holder.

@item @strong{Public Domain}
@anchor{@strong{Public Domain}}

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.

@item @strong{Other Rights}
@anchor{@strong{Other Rights}}

In no way are any of the following rights affected by the license:

@itemize
@item Your fair dealing or fair use rights, or other applicable
copyright exceptions and limitations;

@item The author's moral rights;

@item Rights other persons may have either in the work itself or in
how the work is used, such as publicity or privacy rights.

@end itemize

@end table

@table @asis
@item @strong{Notice}
@anchor{@strong{Notice}}

For any reuse or distribution, you must make clear to others the
license terms of this work.

@end table

A copy of the full license is included in the file as cc-by-sa.txt.

@node DEPENDENCIES
@chapter DEPENDENCIES

GNU @strong{parallel} uses Perl, and the Perl modules Getopt::Long,
IPC::Open3, Symbol, IO::File, POSIX, and File::Temp. For remote usage
it also uses rsync with ssh.

@node SEE ALSO
@chapter SEE ALSO

@strong{ssh}(1), @strong{ssh-agent}(1), @strong{sshpass}(1), @strong{ssh-copy-id}(1),
@strong{rsync}(1), @strong{find}(1), @strong{xargs}(1), @strong{dirname}(1), @strong{make}(1),
@strong{pexec}(1), @strong{ppss}(1), @strong{xjobs}(1), @strong{prll}(1), @strong{dxargs}(1),
@strong{mdm}(1)

@bye
