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
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.
- How to use zip and unzip via command line
- How to use zip and unzip via GUI
|Category||Requirements, Conventions or Software Version Used|
|System||Any Linux distro|
|Other||Privileged access to your Linux system as root or via the |
|Conventions|| # - requires given linux commands to be executed with root privileges either directly as a root user or by use of |
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:
$ sudo apt install zip unzip
$ sudo pacman -S zip unzip
$ 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
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:
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
If you want to extract the files and folders to a particular directory, you can specify the directory path with the
$ unzip archive-name.zip -d /path/to/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:
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."
Make sure you select the zip option in the following menu and choose a name for your archive.
How to unzip via GUI
To unzip, you can simply right click the zip archive and choose "extract here."
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.
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.