How to use zip on Linux

Compressed files with the .zip extension are commonplace throughout Windows systems, as it’s been the native file compression method for the operating system since many years ago. On a Linux system, the nearest equivalent would have to be tar files and various methods of compression like gzip.

There are a few reasons why you may need to create or open .zip files on Linux. When sharing files with a Windows user, it’d definitely be better to send them a .zip file than a file with Linux based compression, and you may come across an occasional zip archive online or from a friend that you need to open.

In this guide, we’ll show you how to use zip on Linux to open or create compressed .zip archives on both the command line and GUI.

In this tutorial you will learn:

  • How to use zip and unzip via command line
  • How to use zip and unzip via GUI

How to use zip on Linux

How to use zip on Linux

Software Requirements and Linux Command Line Conventions
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

How to use zip via command line



Using zip on the command line will involve two different utilities, zip for compressing or “zipping” files and unzip for decompressing or “unzipping” files. Your Linux distro may already come with these packages installed, but not all do. You can run the respective commands on your system to install and/or update the two programs:

On Ubuntu, Debian, and Linux Mint:

$ sudo apt install zip unzip

On Arch Linux and Manjaro:

$ sudo pacman -S zip unzip

On Red Hat, Fedora, and CentOS:

$ sudo dnf install zip unzip

Once the packages have been installed, you can use the following command syntax to compress some files into a zip archive:

$ zip archive-name.zip file1.txt file2.txt file3.txt
Using zip on command line

Using zip on command line



DID YOU KNOW?
Zip files will not preserve file permissions like tar files will. This is one reason why you should stick with tar files on Linux unless you’re looking for cross compatibility.

You can also add directories to a zip archive by using the -r (recursive) option. You can specify as many directories as you’d like. Feel free to also include files in the same command.

$ zip -r directory1 directory2 file1.txt file2.txt

The zip tool has more options available that you can see by simply typing:

$ zip

Or viewing the man page:

$ man zip

How to use unzip

The unzip command is very easy to use; all you need to do is specify the name of the zip archive that you wish to decompress.

$ unzip archive-name.zip
Unzipping an archive on command line

Unzipping an archive on command line



If you want to extract the files and folders to a particular directory, you can specify the directory path with the -d option:

$ unzip archive-name.zip -d /path/to/directory
Unzipping an archive into a specified directory

Unzipping an archive into a specified directory

Just like zip, the unzip tool has a lot more options you may find useful. Type either of these commands for a full rundown:

$ unzip

Or see the man page:

$ man unzip

How to use zip via GUI

Most or every desktop environment should include a way to open and create zip files. In the examples below, we’re using GNOME on Ubuntu, but the instructions should be nearly identical across any desktop environment or Linux distro that you happen to be using.

To create a zip archive: highlight the files you want to compress, right click one of them, and click on “compress.”

Right click the files and click compress

Right click the files and click compress



Make sure you select the zip option in the following menu and choose a name for your archive.

Name the compressed archive and choose zip option

Name the compressed archive and choose zip option

How to unzip via GUI

To unzip, you can simply right click the zip archive and choose “extract here.”

Right click a zip file and choose extract to decompress it

Right click a zip file and choose extract to decompress it

You also have options in the same menu to extract to a different location if you choose. Additionally, you can open the zip archive to browse the contents and extract individual files.

Conclusion

In this guide, we saw how to compress and decompress zip archives via command and GUI on Linux. Zip files are the most used compression format, so it’s very useful to know how to create and open them. Tar files are better for Linux since they are more flexible and preserve file permissions, but chances are that there will be situations where you need to use zip files as well.



Comments and Discussions
Linux Forum