Detalhes do pacote

parallel

flesler3.2kMIT2.3.1

CLI tool to execute shell commands in parallel, based on GNU parallel command

parallel, cli, concurrent, commands

readme (leia-me)

parallel

npm version npm downloads License: MIT Node.js Support GitHub stars GitHub issues

CLI tool to execute shell commands in parallel.

Loosely based on GNU parallel command.

Installation

Using npm:

$ npm install -g parallel

Usage

parallel [options] [command [arguments]] < list_of_arguments
parallel [options] [command [arguments]] (::: arguments)...
cat ... | parallel --pipe [options] [command [arguments]]

Options

-j, --jobs <n>          Max processes to run in parallel (0 for ∞) [default CPUs]
-n, --max-args <args>   Number of input lines per command line [default 1]
-X, --xargs             Multiple arguments with context replace
-d, --delimiter <delim> Input items are terminated by delim [default \n]
-0, --null              Use NUL as delimiter
-q, --quote             Quote each input line in case they contain special caracters
--quote-all             Quote each input line in case they contain special caracters (alias for --quote)
--trim                  Removes spaces, tabs and new lines around the input lines
-t, --print-commands    Print the jobs which parallel is running to stderr
-C, --colsep <regex>    Column separator for positional placeholders [default " "]
-a, --arg-file <file>   Use file as input source instead of stdin
-p, --pipe              Spread input lines to jobs via their stdin
--block <size>          Size of each block in --pipe mode (e.g., 1M, 10K)
-D, --dry-run           Print commands to run without running them
--tag                   Prefix each line of output with the argument that generated it
--shuf                  Randomize the order of jobs
-k, --keep-order        Keep same order as input
--joblog <file>         Log job details (start time, runtime, exit code, command) to file
--bg                    Run commands in background and exit
--delay <secs>          Wait before starting new jobs, secs can be less than 1
--timeout <secs>        If the command runs for longer than secs it will get killed with SIGTERM
--halt-on-error         Kill all jobs and exit if any job exits with a code other than 0
-v, --verbose           Print job commands and timing information to stderr
-s, --shell             Wrap command with shell (supports escaped pipes, redirection, etc.) [experimental]
--help                  Print this message and exit
--version               Print the comand version and exit

Placeholders

{}     the input line
{.}    the input line without extension
{/}    the basename of the input line
{//}   the dirname of the input line
{/.}   the basename of the input line without extension
{#}    the sequence number of the job to run, [1,]
{%}    the job slot number [1, --jobs]
{##}   total number of jobs to be run
{..}   the input line without two extensions (e.g., file.tar.gz → file)
{...}  the input line without up to three extensions (e.g., file.tar.gz.backup → file)
{/..}  the basename without two extensions (e.g., path/file.tar.gz → file)
{/...} the basename without three extensions (e.g., path/file.tar.gz.backup → file)
{+/}   the number of "/" in the input line
{+.}   the number of "." in the input line
{+..}  the extensions removed by {..} (e.g., file.tar.gz → .tar.gz)
{+...} the extensions removed by {...} (e.g., file.tar.gz.bak → .tar.gz.bak)
{n}    nth input column, followed by any operator above (f.e {2/.})

Non-GNU placeholders

{ext}  the extension of the input line
{trim} the input line with leading/trailing whitespace removed
{v}    lower case the value
{^}    upper case the value
{t}    current date-time as a number
{T}    current date-time in ISO format
{d}    current date in ISO format
{r}    random number between 100000 and 999999
{md5}  MD5 hash of the input line
{len}  the length of the input line in characters
{wc}   the word count of the input line

Input from command-line arguments

Input can be provided as command-line arguments preceeded by a :::. Each argument will be considered a separate input line. If you include several :::, parallel will use all the permutations between them as input lines.

You can also read arguments from files using :::: followed by filenames. This allows you to combine multiple input sources.

While GNU´s version also permutates stdin and input files, this version won't. You can also combine multiple input files with :::: to create permutations.

Check examples (8), (10), (11), and (12) to see command-line input in action.

Examples

Basic Operations

(1) Download files simultaneously

cat urls.txt | parallel curl -L {} -o downloads/{/}

(2) Convert video files using all CPU cores

parallel ffmpeg -i {} -c:v libx264 converted/{.}.mp4 ::: *.avi

(3) Compress large log files efficiently

find /var/log -name "*.log" -size +100M | parallel gzip {}

Placeholders & File Processing

(4) Demonstrate path manipulation placeholders

echo -e "/home/user/document.pdf\n/tmp/archive.tar.gz" | \
  parallel echo "Full: {} | Dir: {//} | File: {/} | Name: {/.} | Ext: {ext}"

(5) Multi-extension removal (GNU --plus compatibility)

echo -e "project.tar.gz\nfile.min.js.map" | \
  parallel echo "File: {} | Remove 1: {.} | Remove 2: {..} | Remove 3: {...}"

(6) Count characters in paths and filenames

echo -e "/deep/nested/path/file.min.js\nshallow.txt" | \
  parallel echo "File: {} | Slashes: {+/} | Dots: {+.} | Length: {len}"

Column Processing & Data Manipulation

(7) Process CSV data with column placeholders

echo -e "John,28,Engineer\nSarah,32,Designer" | \
  parallel -C ',' echo "Employee: {1} ({2} years old) works as {3}"

(8) Clean whitespace from messy input

printf "  Alice  \n\t  Bob\t\n" | parallel echo "Original: '{}' | Cleaned: '{trim}'"
# Or
printf "  Alice  \n\t  Bob\t\n" | parallel --trim echo Cleaned: {}

(9) Transform text case and count words

echo -e "Hello World\nFOO BAR" | parallel echo "Text: {} | Lower: {v} | Upper: {^} | Words: {wc}"

Job Management & Control

(10) Preserve output order despite varying job times

seq 5 | parallel --keep-order --shell "sleep \$((6 - {})); echo 'Job {} done'"

(11) Limit concurrency and log job details

parallel -j 2 --joblog build.log echo 'Built {}' ::: app1 app2 app3

(12) Tag output lines with their input source

echo -e "google.com\namazon.com" | parallel --tag ping -c 1 {}

Advanced Features

(13) Process large files in manageable chunks

cat huge_dataset.csv | parallel --pipe --block 10M wc -c

(14) Group multiple arguments per command

echo -e "file1\nfile2\nfile3\nfile4" | parallel -X -j 1 echo "Processing batch:"

(15) Randomize execution order for testing

seq 10 | parallel --shuf --dry-run echo 'Processing {}'

(16) Generate combinations using structured input

echo -e "backup:database\narchive:config\nclone:source" | \
  parallel -C ':' echo "Operation {1} on {2}"

(17) Use built-in time and random placeholders

parallel echo 'Job {} at {T} (ID: {r})' ::: task1 task2

Command-line options

Once a command-line parameter that is not an option is found, then the "command" starts. parallel supports command-line options in all these formats (all equivalent):

  • --trim --jobs 2
  • --trim --jobs=2
  • -t -j 2
  • -tj 2
  • -tj2

Exit code

Just like GNU parallel does, the exit code will be the amount of jobs that failed (up to 101). It means that if any job fails, "global" exit code will be non-zero as well. You can add --halt-on-error to abort as soon as one job fails.

Differences with GNU parallel

GNU Parallel Compatible Features

  • Full placeholder compatibility: {..}, {...}, {/..}, {/...}, {+/}, {+.}, etc.
  • Standard options: -t/--print-commands, --tag, --joblog, -k/--keep-order, --shuf, --block
  • File input: :::: file syntax and -a/--arg-file
  • Job control: -X/--xargs, --halt-on-error, -p/--pipe, -D/--dry-run

🔧 Enhanced Features

  • Better defaults: Default jobs = CPU count (not unlimited)
  • Input flexibility: Supports piped input + ::: arguments together (GNU doesn't)
  • Additional placeholders: {ext}, {v}, {^}, {t}, {T}, {d}, {r}, {md5}, {len}, {wc}, {trim}
  • Simplified usage: --plus not needed (features auto-enabled)

⚠️ Simplified Behaviors

  • --round-robin is implicit when --pipe is used
  • --trim only does full trim (no <n|l|r|lr|rl> options)
  • --halt-on-error is binary (no complex exit condition options)
  • No input permutation between ::: and stdin/--arg-file

License

Copyright (c) 2016, Ariel Flesler All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

  • Neither the name of the organization nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

changelog (log de mudanças)

Changelog

All notable changes to this project will be documented in this file. Dates are displayed in UTC.

v2.3.0

  • Improve placeholder handling and README examples fa76f36
  • Add {+..} and {+...} placeholders for GNU --plus compatibility 1ddc917
  • Implemet a {##} placeholder, require some refactoring for cleaner buffering support 775861e
  • Simplify the default --jobs handling for --help 840ba62
  • Improve option combination validation and --block implies --pipe e7a4881

v2.2.1

  • Improve the readme.js code 74cb1a4
  • Reorganize and improve 'Differences with GNU parallel' section for accuracy and clarity 8e78d9a
  • Split README examples into individual bash blocks for easier copy/paste 4bab99d

v2.2.0

  • Add the package name and version to the --help 592ac0d
  • Move placeholders that are GNU-compliant to the right section 6307b04
  • Fix help not getting the options in one case 3db9936
  • The placeholder documentation in --help and README.md are now programmatically generated 8d5f95c
  • Add {+/} placeholder to count forward slashes (GNU parallel --plus compatibility) 789d289
  • Add {+.} placeholder to count dots (GNU parallel --plus compatibility) f49b58f
  • Add {trim} placeholder to remove leading/trailing whitespace cb4008d

v2.1.0

  • Add professional badges to README for npm, downloads, license, and GitHub stats 6e495ee
  • Refactor README generation in help.js and update README with no leading spaces df5bf58
  • Show help when parallel is run with no arguments and no piped input 2d00685

v2.0.0

  • Add placeholders for double extension handling 29b4481
  • Fix GNU parallel compatibility for {..} placeholder bb8a80f
  • Add {len} placeholder for input line character length fa8919c
  • Add {wc} placeholder for input line word count 9d67904
  • Add --tag option to prefix output lines with input arguments 0b8bedd
  • Use fn.length instead of param property for argument parsing 5013a79
  • Extract semantic parameter names from function signatures for help output b5eba0e
  • Implement --joblog with proper stream closure when jobs finish 8172486
  • Fix critical bug in ::: syntax causing process to hang 994f6bb
  • Add compare.sh script to test against GNU parallel 7ec772a
  • Fix verbose logging in pipe mode to avoid redundant command output f212416
  • Convert all leading tabs to 2 spaces for consistent indentation 04e708d
  • Remove outdated TODOs and refactor dry-run to eliminate code duplication 10316b5
  • Implement --shuf option and update documentation 8c8df24
  • Create an update-readme.js script that auto-updates the README.md based on --help 01996f8
  • Add --quote-all alias for --quote option ad50d49
  • Clean up completed TODO comments and simplify code 07b4699
  • Remove all trailing semicolons for cleaner code style ae10ee4
  • Refactor opts.js to use single module.exports object 27c1adc
  • Replace all var declarations with let/const for ES6 compliance 889d86a
  • Modernize code with template literals and arrow functions 00c99ab
  • Standardize opts properties to match camelCase CLI options and add GNU parallel compatibility features 254c166
  • Update README with new options and improved help format 4f77e0e
  • Add :::: file syntax support for reading arguments from files 8d116b2
  • Add -t/--print-commands flag for GNU parallel compatibility d810936
  • Add --block option for size-based input splitting in pipe mode 83e99bc
  • Update README with new GNU parallel compatibility features c8d40b6
  • Change default jobs from hardcoded 20 to CPU count with CPUs display in help 3afc8a5
  • Polish examples to showcase new features and ensure all work correctly da4b644
  • Add .nvmrc 9eb7796
  • Rename update-readme.js to readme.js 23ebd67
  • Add a new changelog.js script fff7d5a
  • Add a new release.js script d341e10

1.3.1

1.3.0

  • Add various new useful placeholders, that are not in the GNU version 8d3515c

1.2.0

  • Closes #1 #1

1.1.1

  • WIP 1.0.11 d895428
  • Changed the workaround to handle stdin not being piped in 2c64ee0
  • Improved some cryptic variable names 98644ca
  • 1.1.1 ready for release c83b70d

1.0.10

  • WIP 1.0.10 f3605b9
  • Each argument after a ::: is now a separate line 3833d46

1.0.9

  • NPM doesn't accept 1.0.8.1, using 1.0.9 then 0d2e5e6

1.0.8

  • Removed NPM badge, looks ugly 60a3461
  • Changed --trim help description e2e70b0
  • Fixed markdown error on README 4a98ad2
  • --jobs=0 is now supported for an unlimited amount of parallel jobs c0083f3
  • Alternative solution for input bug ec32d19

1.0.7

  • Added and reordered ToDos c418f22
  • Supporting more options formats and added alias for --dry-run 4bc5693

1.0.6

  • gitignore bd8910e
  • Added support for --dry-run option, resulting commands are printed to stdout within runnning. Incompatible with --pipe 5efcff6

1.0.5

  • Initial commit ba74ecd
  • First version a866955
  • Escaping semicolon ad3f182
  • Lots of changes, brought back to 1.0.0 to publish as parallel af5ef5e
  • Reworded 'replacement' as placeholder, is a more suitable name 03ca045
  • Added support for --bg option, jobs are run detached and main process can exit 73e22ed
  • Added ToDos 99a81b3
  • Implemented --delay 5fb24d7
  • Added support for --timeout 475677a
  • Added npm run release for fancy automated releases with tags 3f738d6
  • Added NPM badge e6a7a93
  • Description ba74b96
  • Description c5a9cdc
  • Implemented positional placeholders to split input line in columns 0942218