[英]How to archive large folder (2.4 gb) to multiple separated independent zip-archives
There is a folder with images with the size of 2.4 Gb. 有一个文件夹,其图像大小为2.4 Gb。
The task is to archive via SSH this folder to multiple separated independent zip-archives. 任务是通过SSH将该文件夹归档到多个单独的zip归档文件。
I have tried: 我努力了:
zip -r -s 512m archive.zip folder
This command creates dependent zip-archives: 此命令创建相关的zip归档文件:
archive.z01
archive.z02
archive.z03
archive.z04
archive.zip
But I need to create exactly independent zip-archives for "online web service" which optimizes images. 但是我需要为“在线Web服务”创建完全独立的zip归档文件,以优化图像。 This service requires zip archive and size up to 2Gb.
此服务需要zip存档,最大大小为2Gb。
Could you please suggest a working solution? 您能提出一个可行的解决方案吗?
OS: Linux 操作系统:Linux
Access via: SSH 通过以下方式访问:SSH
Thanks for help. 感谢帮助。
Here's a short script in bash that will do the trick: 这是一个使用bash的简短脚本,可以达到目的:
#!/bin/bash
FILES=`ls *.jpg`
ZIP_PREFIX='archive'
INDEX='1'
MAX_SIZE='512'
for PICT_FILE in $FILES
do
ZIP_NAME=${ZIP_PREFIX}"_"${INDEX}".zip"
ARCH_SIZE=`du -m $ZIP_NAME | cut -f 1`
if [ $ARCH_SIZE -ge $MAX_SIZE ]; then
INDEX=`echo "$INDEX + 1" | bc`
fi
ZIP_NAME=${ZIP_PREFIX}"_"${INDEX}".zip"
zip $ZIP_NAME $PICT_FILE
done
MAX_SIZE is set in Mb You can replace command in 'FILES' with find
or anything else that will provide you with the list of files 在Mb中设置了MAX_SIZE。您可以将“ FILES”中的命令替换为
find
或其他任何可以为您提供文件列表的命令
the.Legend, thanks for the script. the.Legend,感谢您的脚本。
Here is few notices: 这里有几点注意事项:
1. `du -m $ZIP_NAME | cut -f 1`
Returns 1 for files with the size less then 1 Mb. 对于大小小于1 Mb的文件,返回1。
2. INDEX=`echo "$INDEX + 1" | bc
Does not work in bash in linux. 在Linux中的bash中不起作用。
Here is updated script which was tested in linux: 这是经过Linux测试的更新脚本:
#!/bin/bash
FILES=`find ./image/`
ZIP_PREFIX='example.com.image'
INDEX='1'
MAX_SIZE='512000' # 512 Mb
for PICT_FILE in $FILES
do
ZIP_NAME=${ZIP_PREFIX}"_"${INDEX}".zip"
ARCH_SIZE=`du -k $ZIP_NAME | cut -f 1`
# echo $ARCH_SIZE
# echo $MAX_SIZE
if [ $ARCH_SIZE -ge $MAX_SIZE ]; then
INDEX=$((INDEX + 1))
fi
ZIP_NAME=${ZIP_PREFIX}"_"${INDEX}".zip"
zip $ZIP_NAME $PICT_FILE
done
The result is: 结果是:
http://example.com/example.com.image_1.zip [500Mb]
http://example.com/example.com.image_2.zip [500Mb]
http://example.com/example.com.image_3.zip [500Mb]
http://example.com/example.com.image_4.zip [227Mb]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.