简体   繁体   English

如何将大文件夹(2.4 GB)归档到多个单独的zip归档文件

[英]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.

相关问题 如何将多个库存档(.a)打包到一个存档文件中? - How to pack multiple library archives (.a) into one archive file? 如何在基于 4GB 大小限制的文件夹中创建多个 ZIP 文件? - How to create multiple ZIP files in a folder based on 4GB size restriction? 如何压缩包含12GB以上数据的文件夹 - How to zip folder that contains more than 12GB data 如何在没有中间文件夹的情况下将文件添加到zip存档 - How to add files to zip archive without a intermediate folder 如何从 linux 服务器上的大 (30Gb+) zip 文件中提取文件 - how to extract files from a large (30Gb+) zip file on linux server 如何压缩多个文件夹,每个文件夹都有自己的 zip 存档? - How to compress multiple folders, each into its own zip archive? 如何区分zip档案中的xlsx和docx文件? - How to distinguish xlsx and docx files from zip archives? 如何提取添加到 zip 存档的最后一个文件 - How to extract last file added to an zip archive 如何在多个文件夹层次结构中删除除最后几个文件以外的zip文件 - How to delete the zip files except last few, in multiple folder hierarchy 如何将目录中的大量zip文件移动到bash中指定数量的多个子目录中? - How do I move a large number of zip files in a directory to a specified number of multiple subdirectories in bash?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM