How to Install and Use Zip on Ubuntu 24.04

Zip is a command line tool that allows you to compress files or folders into a single archive file with .zip extension. People use the zip utility to bundle their files together so that they can easily share or transfer the files to other people. The compression reduces the size of the file, thus creating multiple zip files will help reduce the space on your system. 

For the Ubuntu 24.04 system, having the zip utility installed will help you zip files and folders using the zip command. It provides you with several options that you can use to change the behavior of the zip command.

Read this blog to find:

How to Install Zip on Ubuntu 24.04

By default, the zip utility is installed on Ubuntu 24.04, however, if the utility is deleted accidentally, you can reinstall it again from the following command:

sudo apt install zip -y

To confirm zip utility is installed on Ubuntu, you can run the below-given command:

zip --version

How to Use Zip on Ubuntu 24.04

The zip command can be used with different options or flags to get the desired zip file on your system. The basic syntax to create a zip file on Ubuntu is provided below:

zip [zip_filename] [filename]

Here, replace the zip_filename with the desired zip file you want to create, and the filename with the files you want to include separated by a space.

zip files.zip file1.txt file2.txt file3.txt

To confirm the zip file is successfully created, you can use the ls command inside the directory where you have created the zip file on Ubuntu:

l s

If you want to delete a specific file from the zip file, you can use the -d flag followed by the zip file name and the name of the file you want to delete. 

zip -d [zip_filename] [file to delete]

As an example, we have deleted a file file3.txt from the zip file files.zip using the following command:

zip -d files.zip file3.txt

If you want to add a file to the zip file on Ubuntu, you can do it easily by adding the -u flag followed by the zip filename and the filename you want to include. As an example, we have added the file4.txt file to the zip file named files.zip using the following command:

zip -u files.zip file4.txt

To check for the content inside the zip file, you can use the unzip command with -l flag and the zip filename, as given below:

unzip -l files.zip

If you want to add multiple files with the same format all at once into the zip file, you can use the -m flag followed by the zip filename and the wild card character and file format. 

In the following examples, we have added all the .txt files into the zip file named myfiles.zip:

zip -m myfiles.zip *.txt

To get a detailed verbose output, you can use the -v flag with the zip command you want to use. Here, in the following command, we have used the -v flag with the zip command that adds multiple files of the same format all at once:

zip -vm myfiles.zip *.txt

Additional Flags or Options Used with the Zip Command

There are some other additional options you can use with the zip command, these are provided in the table below:

OptionsDescriptionExamples
-rRecursively zip a directory.zip -r my_archive.zip my_folder
-xExclude files from the zip.zip -r my_archive.zip -x unwanted_file.txt
-sSplits the archive into smaller segments.zip -s 10m my_archive.zip
-gGrows an existing archive by adding a new file to the archive without creating a new one.zip -g my_archive.zip new_file.txt
-fUpdate files in an existing zip archive.zip -u my_archive.zip updated_file.txt
-qEnable quiet mood.zip -q my_archive.zip file1.txt file2.txt

For more details, you can open the zip manual using the following command:

man zip

Bonus Method: How to Create a Zip File on Ubuntu 24.04 from GUI

Apart from using the zip command to create a zip file on Ubuntu from the terminal, you can use the GUI to perform a similar action. Follow the steps given below to create a zip file on Ubuntu from the GUI:

Step 1: First, navigate to the directory where your files are placed, and you want to combine them in a zip file.

Step 2: Then inside the directory, select the files all at once and right-click from the mouse or touchpad. Then choose the Compress option:

Step 3: Now type the name of your achieve file in the Archive name box:

Step 4: After adding the filename, click on the Create button:

This will create a zip file on your system:

Conclusion

Zip is a powerful command line tool used for compressing files and directories in an archive file. The zip utility is preinstalled on Ubuntu 24.04, however, it can be reinstalled again from the repository in case of accidental deletion. In this guide, we have explored the method to install and use zip on Ubuntu 24.04. For usage, we have discussed some examples of zip commands to help the user learn different ways to use this command on their systems. Apart from that, we have also discussed an additional method of creating a zip file from the GUI. It will help the user choose the method according to their choice for creating a zip file on Ubuntu.