When compressing large files on a Linux system, it can be handy to split them into multiple blocks of a specific size. This is especially true for squeezing a large archive onto multiple discs, or uploading a large archive online in chunks.
Linux makes this possible with tar files, as we’ve seen in our split tar archive into multiple blocks guide, but you can also do it with zip files.
In this guide, we’ll see the step by step instructions to create a zip archive split into multiple blocks. We’ll also go through the process of unzipping the split archive.
In this tutorial you will learn:
- How to split zip archives into multiple files
- How to open split zip archives
Category | Requirements, Conventions or Software Version Used |
---|---|
System | Any Linux distro |
Software | zip, unzip |
Other | Privileged access to your Linux system as root or via the sudo command. |
Conventions |
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command$ – requires given linux commands to be executed as a regular non-privileged user |
Split zip archives into multiple blocks
To split zip archives into multiple files, we’ll use the -s
(splitsize) option of the zip
command. Before using the zip utility, you’ll need to make sure it’s installed on your system. You can check our guide on how to use zip on Linux for help with that.
Let’s look at an example. This command will split a zip compressed archive into 5MB chunks:
$ zip -r -s 5m myfiles.zip example-dir/
In our example, we split three large text files into 5MB zip archives. As you can see, the files end up with names like:
$ ls myfiles* myfiles.z01 myfiles.z02 myfiles.z03 myfiles.z04 myfiles.z05 myfiles.zip
In our command, the -r
option is for recursive, which we need for zipping a directory. The -s
option, as discussed, splits the zip archive into files of a specified size. In our case, we used 5 megabytes, but you can substitute any number you’d like.
Open split zip archives
To open the split zip archive that we’ve created, we need to use the unzip
utility. If it’s not already installed on your system, you can check our guide on how to unzip a zip file for help.
First, use the zip
command to combine the split zip files into a single zip archive. In the example below, we combine the myfiles.zip
archives into single-archive.zip
.
$ zip -F myfiles.zip --out single-archive.zip
Now we can use unzip
to open our combined archive.
$ unzip single-archive.zip
Closing Thoughts
In this guide, we saw how to make zip archives on Linux, and have them split into multiple blocks of a certain size. The zip
command on Linux is robust enough to include this option, so splitting archives and combining them later ends up being very easy once you know the options to use.