HOME

TheInfoList



OR:

GNU parallel is a
command-line A command-line interpreter or command-line processor uses a command-line interface (CLI) to receive commands from a user in the form of lines of text. This provides a means of setting parameters for the environment, invoking executables and pro ...
driven utility for
Linux Linux ( or ) is a family of open-source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically packaged as a Linux distribution, which ...
and other
Unix-like A Unix-like (sometimes referred to as UN*X 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 Unix-li ...
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 ** Thin-shell structure Science Biology * Seashell, a hard ou ...
scripts or commands in parallel. GNU parallel is
free software Free software or libre software is computer software distributed under terms that allow users to run the software for any purpose as well as to study, change, and distribute it and any adapted versions. Free software is a matter of liberty, no ...
, written by Ole Tange in
Perl Perl is a family of two high-level, general-purpose, interpreted, dynamic programming languages. "Perl" refers to Perl 5, but from 2000 to 2019 it also referred to its redesigned "sister language", Perl 6, before the latter's name was offici ...
. It is available under the terms of
GPLv3 The GNU General Public License (GNU GPL or simply GPL) is a series of widely used free software licenses that guarantee end users the four freedoms to run, study, share, and modify the software. The license was the first copyleft for general us ...
.


Usage

The most common usage is to replace the shell loop, for example while read x; do do_something "$x" done < list , process_output to the form of < list parallel do_something , process_output 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 pexec is a command-line utility for Linux and other Unix-like operating systems which allows the user to execute shell commands in parallel. The specified code can be executed either locally or on remote hosts, in which case ssh is used to build a ...
. The program parallel features also * grouping of
standard output In computer programming, standard streams are interconnected input and output communication channels between a computer program and its environment when it begins execution. The three input/output (I/O) connections are called standard input (stdin ...
and
standard error The standard error (SE) of a statistic (usually an estimate of a parameter) is the standard deviation of its sampling distribution or an estimate of that standard deviation. If the statistic is the sample mean, it is called the standard error ...
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 Directory may refer to: * Directory (computing), or folder, a file system structure in which to store computer files * Directory (OpenVMS command) * Directory service, a software application for organizing information about a computer network's u ...
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 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 a ...
. 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 (also null terminator) is a control character with the value zero. It is present in many character sets, including those defined by the Baudot and ITA2 codes, ISO/IEC 646 (or ASCII), the C0 control code, the Universal Coded Ch ...
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 xargs (short for "extended arguments" ) is a command on Unix and most Unix-like operating systems used to build and execute commands from standard input. It converts input from standard input into arguments to a command. Some commands such as gr ...
*
pexec pexec is a command-line utility for Linux and other Unix-like operating systems which allows the user to execute shell commands in parallel. The specified code can be executed either locally or on remote hosts, in which case ssh is used to build a ...
*
GNU Queue Werner G. Krebs (born c. 1977) is an American data scientist. He is currently CEO of data science and artificial intelligence startup Acculation, Inc. and has previously held positions at what are now Virtu Financial, Bank of America, and the San D ...


References


External links

*
Project page and manual page of GNU parallel
{{GNU Free software programmed in Perl
parallel Parallel is a geometric term of location which may refer to: Computing * Parallel algorithm * Parallel computing * Parallel metaheuristic * Parallel (software), a UNIX utility for running programs in parallel * Parallel Sysplex, a cluster of IBM ...
Linux process- and task-management-related software Articles containing video clips