Share to: share facebook share twitter share wa share telegram print page

 

GNU parallel

Parallel
Developer(s)GNU Project
Stable release
20241022[1] / 21 October 2024; 3 months ago (2024-10-21)
Repository
Written inPerl
Operating systemGNU
TypeUtility
LicenseGPLv3
Websitewww.gnu.org/software/parallel/ Edit this on Wikidata

GNU parallel is a command-line utility for Linux and other Unix-like operating systems which allows the user to execute shell scripts or commands in parallel. GNU parallel is free software, written by Ole Tange in Perl. It is available under the terms of GPLv3.[2]

Usage

Introduction video, Part 1
Introduction video, Part 2

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 and 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 and its subdirectories whose name end in .foo for occurrences of the string bar. The parallel command will work as expected unless a file name contains a newline. In order to avoid this limitation one may use:

find . -name "*.foo" -print0 | parallel -0 grep bar

The above command uses the null character 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

References

  1. ^ Tange, Ole (21 Oct 2024). "GNU Parallel 20241022 ('Sinwar Nasrallah') released [stable]". parallel (Mailing list).
  2. ^ "GNU Parallel". GNU.org.
Kembali kehalaman sebelumnya


Index: pl ar de en es fr it arz nl ja pt ceb sv uk vi war zh ru af ast az bg zh-min-nan bn be ca cs cy da et el eo eu fa gl ko hi hr id he ka la lv lt hu mk ms min no nn ce uz kk ro simple sk sl sr sh fi ta tt th tg azb tr ur zh-yue hy my ace als am an hyw ban bjn map-bms ba be-tarask bcl bpy bar bs br cv nv eml hif fo fy ga gd gu hak ha hsb io ig ilo ia ie os is jv kn ht ku ckb ky mrj lb lij li lmo mai mg ml zh-classical mr xmf mzn cdo mn nap new ne frr oc mhr or as pa pnb ps pms nds crh qu sa sah sco sq scn si sd szl su sw tl shn te bug vec vo wa wuu yi yo diq bat-smg zu lad kbd ang smn ab roa-rup frp arc gn av ay bh bi bo bxr cbk-zam co za dag ary se pdc dv dsb myv ext fur gv gag inh ki glk gan guw xal haw rw kbp pam csb kw km kv koi kg gom ks gcr lo lbe ltg lez nia ln jbo lg mt mi tw mwl mdf mnw nqo fj nah na nds-nl nrm nov om pi pag pap pfl pcd krc kaa ksh rm rue sm sat sc trv stq nso sn cu so srn kab roa-tara tet tpi to chr tum tk tyv udm ug vep fiu-vro vls wo xh zea ty ak bm ch ny ee ff got iu ik kl mad cr pih ami pwn pnt dz rmy rn sg st tn ss ti din chy ts kcg ve 
Prefix: a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9