Skip to content

Instantly share code, notes, and snippets.

@atheiman
Last active February 11, 2024 01:24
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save atheiman/dda0a9bac4d1dbe04648617d86d47b56 to your computer and use it in GitHub Desktop.
Save atheiman/dda0a9bac4d1dbe04648617d86d47b56 to your computer and use it in GitHub Desktop.
GNU Parallel install and usage notes
# Install GNU parallel in a CentOS-based docker container (e.g. for CI/CD)
# install needed dependencies
yum install -q -y bzip2 tar make perl
# download source
curl -s -L -o /tmp/parallel.tar.bz2 https://ftpmirror.gnu.org/parallel/parallel-latest.tar.bz2
# extract source
tar -C /tmp -xjf /tmp/parallel.tar.bz2
# navigate into extracted source
cd /tmp/parallel-*
# build and install
./configure && make && make install
# return to previous directory
cd -
# verify version of parallel installed
parallel --version | head -1
# get past annoying parallel citation prompt
echo 'will cite' | parallel --citation &> /dev/null || true
# example simple usage
parallel echo ::: a b c
# Run jobs in 5 parallel "job slots", different color for the prefix of each job's output. Unique colors will only be
# used up to 8 parallel job slots (there are usually only 8 possible terminal colors).
# {%} prints the jobs slot number in the "tagstring"
# {} prints the job input, it can be modified with other replacement strings (e.g. to remove the path from a filename)
# https://www.gnu.org/software/parallel/parallel_tutorial.html#the-7-predefined-replacement-strings
parallel -j 5 --tagstring '\033[3{%}m[Job Slot {%}] [{}]\033[0m' --linebuffer head -3 ::: $(find -L /etc -type f | head -8)
# Run the same command 25 times in batches of 5. Prints job number in tag string.
seq 1 25 | parallel --tagstring '(Job Number {#})' -j 5 --linebuffer -n 0 'sleep 3 && openssl rand -hex 16'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment