Naf*_*Kay 4 scripting gpg parallelism
我正在运行这样的东西:
find . -maxdepth 1 -type f -note -iname "*.gpg" | sort | while read file ; do
echo "Encrypting $file..."
gpg --trust-model always --recipient "me@myself.com" --output "$file.gpg" \
--encrypt "$file" && rm "$file"
done
Run Code Online (Sandbox Code Playgroud)
这运行良好,但似乎 GPG 并未优化为使用多核进行加密操作。我正在加密的文件大小约为 2GB,而且我有相当多的文件。我希望能够并行运行 X 个作业来加密文件然后删除它们。我该如何做到这一点,将限制设置为一次 8 个工作?
如果你安装了GNU Parallel工具,你可以很容易地完成你想要完成的工作:
$ find . -maxdepth 1 -type f -note -iname "*.gpg" | sort | \
parallel --gnu -j 8 --workdir $PWD ' \
echo "Encrypting {}..."; \
gpg --trust-model always \
--recipient "me@myself.com" --output "{}.gpg" \
--encrypt "{}" && rm "{}" \
'
Run Code Online (Sandbox Code Playgroud)
以上是获取 的输出find
并将其运行到parallel
,并且一次运行 8。任何地方都会出现{}
正在传递的文件名,find
将替换{}
这些位置中的 。