Differences between revisions 3 and 11 (spanning 8 versions)
Revision 3 as of 2018-07-14 23:07:39
Size: 265
Editor: SamatJain
Comment:
Revision 11 as of 2019-04-28 00:16:11
Size: 1376
Editor: SamatJain
Comment: Check MP3s using parallel, recursively
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
find . -maxdepth 1 -print0 | parallel -0 -j4 echo cp -avn {} $dst # Because we are copying the current directory, make sure $dst is correct
parallel --bar -j4 cp -avn -- "{}" "$dst" ::: *
# Old idea, much slower
find . -maxdepth 1 -mindepth 1 -print0 | parallel -q0 -j4 echo cp -avn "{}" "$dst"
Line 6: Line 9:
parallel -m mp3check -Sqe ::: *mp3 parallel -X mp3check -Sqe ::: *mp3
# Likewise, but recursively
find . -iname '*mp3' -print0 | parallel -0 -X mp3check -Sqe
Line 10: Line 15:

# Using a file (one per line) of arguments
parallel 'some-command {}' ::: list-of-arguments.txt

# Parallel equivalent of
# `find $DIRECTORY -type f -exec sha1sum '{}' \; > $DIRECTORY.sha1`
find $DIRECTORY -type f -print0 | parallel -q0 -k sha1sum > $DIRECTORY.sha1

# Quickly get hash of large file. Reads in 1G chunks, multiple CPUs, and outputs 1 hash.
parallel --block=1G --pipepart -a $LARGE_FILE --progress --recend '' -k sha1sum | sha1sum
Line 11: Line 26:

## useful options

 * `-X`: Multiple arguments per job, spread evenly across jobs, with context replace to replace "{}".
 * `-m`: Multiple arguments per job, spread evenly across jobs. Preferably use `-X`.
 * `--xargs`: Multiple arguments per job emulating xargs behavior; as many arguments per job as possible

 * `-n`: Limits number of arguments per job, use w/ `-X`, `--xargs`, or `-m`

   1 # Parallel copy
   2 # Because we are copying the current directory, make sure $dst is correct
   3 parallel --bar -j4 cp -avn -- "{}" "$dst" ::: *
   4 # Old idea, much slower
   5 find . -maxdepth 1 -mindepth 1 -print0 | parallel -q0 -j4 echo cp -avn "{}" "$dst"
   6 
   7 # Check MP3s in parallel, many arguments per invocation
   8 parallel -X mp3check -Sqe ::: *mp3
   9 # Likewise, but recursively
  10 find . -iname '*mp3' -print0 | parallel -0 -X mp3check -Sqe
  11 
  12 # Run commands in a file parallel
  13 parallel < commands.txt
  14 
  15 # Using a file (one per line) of arguments
  16 parallel 'some-command {}' ::: list-of-arguments.txt
  17 
  18 # Parallel equivalent of
  19 # `find $DIRECTORY -type f -exec sha1sum '{}' \; > $DIRECTORY.sha1`
  20 find $DIRECTORY -type f -print0 | parallel -q0 -k sha1sum > $DIRECTORY.sha1
  21 
  22 # Quickly get hash of large file. Reads in 1G chunks, multiple CPUs, and outputs 1 hash.
  23 parallel --block=1G --pipepart -a $LARGE_FILE --progress --recend '' -k sha1sum | sha1sum

  • -X: Multiple arguments per job, spread evenly across jobs, with context replace to replace "{}".

  • -m: Multiple arguments per job, spread evenly across jobs. Preferably use -X.

  • --xargs: Multiple arguments per job emulating xargs behavior; as many arguments per job as possible

  • -n: Limits number of arguments per job, use w/ -X, --xargs, or -m

SamatsWiki: CheatSheet/GNUParallel (last edited 2019-04-28 00:16:11 by SamatJain)