linuxbashgzip

Gzip with all cores


I have a set of servers filled each with a bunch of files that can be gzipped. The servers all have different numbers of cores. How can I write a bash script to launch a gzip for each core and make sure the gzips are not zipping the same file?


Solution

  • If you are on Linux, you can use GNU's xargs to launch as many processes as you have cores.

    CORES=$(grep -c '^processor' /proc/cpuinfo)
    find /source -type f -print0 | xargs -0 -n 1 -P $CORES gzip -9