ubuntu zip folder

Zipping is a popular way to archive files. On Ubuntu, you can zip files using compression algorithms like store, deflate, and bzip2. These allow you to archive files with different levels of compression. Ubuntu’s zip tool also supports options for various useful tasks like encrypting the archive or splitting it into multiple parts.

Zip Files Graphically

Zipping files using the file manager is very easy. Just select the files and folders you want to archive, right-click, and select Compress.

Aside from the default .zip format, you can choose to password-protect the archive or select other archiving formats like .tar.xz or .7z. Once you’ve made your choices, name the archive and press Create.

The compression ratio will vary depending on the files being archived. For instance, text files usually are compressed at a 2:1 ratio. A compression ratio of 1:1 means the archive’s size will be almost the same as the original files.

Use Zip Command

The GUI compression tool is convenient, but it’s fairly limited. If you want to perform advanced tasks related to file packaging, the CLI zip utility will be a better fit. The basic syntax for zip is

zip archivename file1 file2

When zipping folders, you’ll want to use the --recurse-paths flag so that zip travels the directory structure recursively. The following command zips folder1, folder2, and all their contents in an archive named myarchive.

zip -r myarchive folder1 folder2

You can also zip files and folders together. For instance, you could zip all files and folders in the working directory to an archive named myarchive with a wildcard.

zip -r myarchive *

If you want to zip certain types of files only, you could use a wildcard and specify the extension like so

zip myarchive *.mp3

Set Compression Level

Compression speed is measured on a scale of -0 to -9, where -0 represents no compression (store) and -9 represents the slowest compression speed. The default compression mode is deflate (-6).

You can control the compression speed by specifying the level like so

zip -7 myarchive file1 file2

If you want to use bzip2, you can specify the compression method using the -Z flag.

zip -Z bzip2 myarchive file1

Encrypt Archive

In Zip 3.0, the --encrypt flag encrypts the contents of the zip archive using a cipher called ZipCrypto.

ZipCrypto isn’t really secure, but it’s still useful to have an extra layer of password protection on your files. New releases like Zip 3.1 have added support for AES-256 encryption, which is much more secure. 

In either case, encrypting the archive is very easy. Simply use the -e flag like so

zip -e myarchive file1

Split Archive

When archiving a lot of files, splitting the archive into multiple smaller parts makes it much easier to move them around. You can use the --split-size flag and specify the split sizes to do this.

zip -s 800m -r myarchive folder1

Let’s say you have a directory named folder1 (size 3.6 GB). The above example splits the archive into roughly 800MB-sized files named myarchive.z01, myarchive.z02, myarchive.z03, and myarchive.z04.

We used m to specify 800 megabytes in our example, but you can also use k (kilobytes), g (gigabytes), or t (terabytes) as appropriate in your case.

How to Unzip A File

Unzipping a zip archive is as simple as right-clicking the zip file and selecting the Extract option.

If you want to extract the files from the terminal, you can use the unzip command like so

unzip myarchive.zip

You can extract the files to a different directory with the -d flag.

unzip myarchive.zip -d /home/anup/Downloads

Or, if you want to check the contents of the archive before extracting the files, you can use the -l flag to list the files.

unzip -l myarchive.zip
Anup Thapa

Senior Writer

Anup Thapa is a Linux enthusiast with an extensive background in computer hardware and networking. His goal is to effectively communicate technical concepts in a simplified form understandable by new Linux users. To this end, he mainly writes beginner-friendly tutorials and troubleshooting guides. Outside of work, he enjoys reading up on a range of topics, traveling, working out, and MOBAs.