Skip to main content
practice.schlesier.ca
Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

parallel

A nice overview

Easily execute commands per file

parallel execution of command on each txt file

parallel commmand {} ::: *.txt

Track slot number % and job number #

> parallel echo {%} {#} {} ::: *.txt

1 1 foo.txt
2 2 fee.txt
1 3 fi.txt
2 4 fum.txt

Manage max slots with -j

Slots default to the number of available processors

> parallel -j 1 echo {} ::: *.txt

1 1 foo.txt
1 2 fee.txt
1 3 fi.txt
1 4 fum.txt

Check for correctness using --dryrun

parallel --dryrun echo {} ::: *.txt

File and path variations

Insert filename with {}

> parallel echo {} ::: **/*

a.txt
b.txt
subdir/c.txt
subdir/d.txt

Strip extension by adding .

> parallel echo {.} ::: **/*

a
b
subdir/c
subdir/d

Strip path by adding /

> parallel echo {/} ::: **/*

a.txt
b.txt
c.txt
d.txt

Strip path and extension by adding /.

> parallel echo {/.} ::: **/*

a
b
c
d

Keep only path by adding //

> parallel echo {//} ::: **/*

.
.
subdir
subdir