GNU parallel is a
command-line utility for
Linux
Linux ( ) is a family of open source Unix-like operating systems based on the Linux kernel, an kernel (operating system), operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically package manager, pac ...
and other
Unix-like
A Unix-like (sometimes referred to as UN*X, *nix or *NIX) operating system is one that behaves in a manner similar to a Unix system, although not necessarily conforming to or being certified to any version of the Single UNIX Specification. A Uni ...
operating systems which allows the user to execute
shell
Shell may refer to:
Architecture and design
* Shell (structure), a thin structure
** Concrete shell, a thin shell of concrete, usually with no interior columns or exterior buttresses
Science Biology
* Seashell, a hard outer layer of a marine ani ...
scripts or commands
in parallel. GNU parallel is
free software
Free software, libre software, libreware sometimes known as freedom-respecting software is computer software distributed open-source license, under terms that allow users to run the software for any purpose as well as to study, change, distribut ...
, written by Ole Tange in
Perl
Perl is a high-level, general-purpose, interpreted, dynamic programming language. Though Perl is not officially an acronym, there are various backronyms in use, including "Practical Extraction and Reporting Language".
Perl was developed ...
. It is available under the terms of
GPLv3
The GNU General Public Licenses (GNU GPL or simply GPL) are a series of widely used free software licenses, or ''copyleft'' licenses, that guarantee end users the freedom to run, study, share, or modify the software. The GPL was the first ...
.
Usage
The most common usage is to replace the shell loop, for example
while read x; do
do_something "$x"
done < list
to the form of
cat list , parallel do_something
where the file
list
contains arguments for
do_something
and where
process_output
may be empty.
Scripts using parallel are often easier to read than scripts using
pexec.
The program parallel features also
* grouping of
standard output Standard may refer to:
Symbols
* Colours, standards and guidons, kinds of military signs
* Standard (emblem), a type of a large symbol or emblem used for identification
Norms, conventions or requirements
* Standard (metrology), an object t ...
and
standard error
The standard error (SE) of a statistic (usually an estimator of a parameter, like the average or mean) is the standard deviation of its sampling distribution or an estimate of that standard deviation. In other words, it is the standard deviati ...
so the output of the parallel running jobs do not run together;
* retaining the order of output to remain the same order as input;
* dealing nicely with filenames containing special characters such as space, single quote, double quote, ampersand, and UTF-8 encoded characters;
By default, parallel runs as many jobs in parallel as there are
CPU cores.
Examples
find . -name "*.foo" , parallel grep bar
The above is the parallel equivalent to:
find . -name "*.foo" -exec grep bar +
This searches in all files in the current
directory and its subdirectories whose name end in
.foo
for occurrences of the
string
String or strings may refer to:
*String (structure), a long flexible structure made from threads twisted together, which is used to tie, bind, or hang other objects
Arts, entertainment, and media Films
* ''Strings'' (1991 film), a Canadian anim ...
bar
. The parallel command will work as expected unless a file name contains a
newline
A newline (frequently called line ending, end of line (EOL), next line (NEL) or line break) is a control character or sequence of control characters in character encoding specifications such as ASCII, EBCDIC, Unicode, etc. This character, or ...
. In order to avoid this limitation one may use:
find . -name "*.foo" -print0 , parallel -0 grep bar
The above command uses the
null character
The null character is a control character with the value zero. Many character sets include a code point for a null character including Unicode (Universal Coded Character Set), ASCII (ISO/IEC 646), Baudot, ITA2 codes, the C0 control code, and EB ...
to delimit file names.
find . -name "*.foo" , parallel -X mv /tmp/trash
The above command expands
with as many arguments as the command line length permits, distributing them evenly among parallel jobs if required. This can lower process overhead for short-lived commands that take less time to finish than they do to launch.
find . -maxdepth 1 -type f -name "*.ogg" , parallel -X -r cp -v -p /home/media
The command above does the same as:
cp -v -p *.ogg /home/media
However, the former command which uses
find
/
parallel
/
cp
is more resource efficient and will not halt with an error if the expansion of *.ogg is too large for the shell.
See also
*
xargs
*
pexec
*
GNU Queue
References
External links
*
Project page and manual page of GNU parallel
{{GNU
Free software programmed in Perl
parallel
Linux process- and task-management-related software
Articles containing video clips