官方文档:https://www.gnu.org/software/parallel/parallel_tutorial.html
安装
(wget -O - pi.dk/3 || curl pi.dk/3/ || fetch -o - http://pi.dk/3) | bash
安装完成后就是一个一万多行的perl脚本,把脚本复制到其他机器一样可以用。
各种应用请查看官方文档。
各种参数请查看man文档。
这里引用random233的博客https://www.jianshu.com/p/c5a2369fa613的用法示例:
1. 传参数模式
seq 5 |parallel echo test_{} 2>/dev/null #结果 test_1 test_2 test_3 test_4 test_5 #由于使用parallel命令会打印出一大堆作者的话,所以直接把标准错误丢弃,以屏蔽这些没用的输出。
#{}是占位符,表示传参数的位置。
2. 管道模式
cat mylog | grep pattern cat my_large_log | parallel --pipe grep pattern #以上两条结果相同,只是parallel会多核并行执行。
3. random233还提到一个很有用的用法,测并发。
seq 3 |parallel -n 0 curl -I www.baidu.com #-n 传递的最大参数个数。-n 0表示不传参数。