具有所有核心的Gzip [英] Gzip with all cores

查看:80
本文介绍了具有所有核心的Gzip的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组服务器,每个服务器中都装有一堆可以压缩的文件.服务器均具有不同数量的核心.如何编写bash脚本为每个核心启动gzip,并确保gzip没有压缩相同的文件?

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?

推荐答案

如果您使用的是Linux,则可以使用GNU的xargs启动与内核一样多的进程.

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

  • 查找-print0/xargs -0可以防止文件名中的空格
  • xargs -n 1表示每个文件一个gzip进程
  • xargs -P指定作业数
  • gzip -9表示最大压缩
    • find -print0 / xargs -0 protects you from whitespace in filenames
    • xargs -n 1 means one gzip process per file
    • xargs -P specifies the number of jobs
    • gzip -9 means maximum compression
    • 这篇关于具有所有核心的Gzip的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆