Answers:
您可以使用GNU parallel来执行此操作,因为它可以限制作业的元素数量并提供作业编号(用于唯一的zip存档名称):
$ touch $(seq 20)
$ find . ! -name "*.zip" -type f -print0 | parallel -0 -N 5 zip arch{#} {}
adding: 1 (stored 0%)
adding: 10 (stored 0%)
adding: 11 (stored 0%)
adding: 12 (stored 0%)
adding: 13 (stored 0%)
adding: 14 (stored 0%)
adding: 15 (stored 0%)
adding: 16 (stored 0%)
adding: 17 (stored 0%)
adding: 18 (stored 0%)
adding: 19 (stored 0%)
adding: 2 (stored 0%)
adding: 20 (stored 0%)
adding: 3 (stored 0%)
adding: 4 (stored 0%)
adding: 5 (stored 0%)
adding: 6 (stored 0%)
adding: 7 (stored 0%)
adding: 8 (stored 0%)
adding: 9 (stored 0%)
$ ls
1 11 13 15 17 19 20 4 6 8 arch1.zip arch3.zip
10 12 14 16 18 2 3 5 7 9 arch2.zip arch4.zip
该选项-N 5
将每个档案的文件数限制为5,并显示zip
在以下位置:{}
该{#}
(逐字,而不是被你调用时更换),由工号代替,造成arch1.zip
,arch2.zip
等等。
串联的-print0
选项find
和-0
选项可parallel
确保正确处理带有特殊字符的文件名。
sudo apt-get install parallel
。
arch{13}
?您确实需要使用#
角色。您正在使用什么外壳?
仅限外壳程序:通过(位置参数范围)处理一批COUNT个文件"${@:START:COUNT}"
,shift COUNT
同时增加一个计数器c
来命名档案:
设置-* c = 1 而(($#)); 做 如果[$#-ge COUNT ];然后 zip $ {c} .zip“ $ {@:1:COUNT }” c = $((c + 1)) 转移COUNT 其他 zip $ {c} .zip“ $ {@}” 移$# 科幻 做完了