Linux Commands Ubuntu

​​How to Zip Files and Directories in Linux/Ubuntu?

How to Zip Files and Directories in Linux

Files are compressed into archives resulting in conservation of storage space and bandwidth. Software packages are usually available to download in compressed archives from the software developer’s website. Compressed archives save time by enabling faster downloading. There are many archive formats for data compression. “.zip” is a popular archive format as it is cross platform compatible. “.zip” uses the “DEFLATE” compression algorithm.

This article will demonstrate compressing data i.e., files and directories using .zip archive format on Linux/Ubuntu 22.04 LTS. This article will discuss:

  • How to Zip Files/Directories in Ubuntu 22.04 Terminal?
  • How to Zip Files/Directories in Ubuntu Using 22.04 GUI?

How to Zip Files/Directories in Ubuntu 22.04 Terminal?

The following sections will discuss creating Zip Archives from multiple files, single and multiple directories by using the command line:

How to Zip Files in Ubuntu 22.04 via Terminal?

Zip” command is used to compress files via Terminal. For example, files File1, File2, File3, File4, and File5 can be compressed to create a zipped archive “CompressedFile.zip” by executing the following command:

$ zip CompressedFile.zip *.txt

The above command comprises of:

  • zip: tar command line tool.
  • CompressedFile.zip: Name of compressed archive.
  • *.txt: selects all the txt files present in the directory.

From the above image, it can be seen that File1.txt, File2.txt, File3.txt, File4.txt, and File5.txt are compressed to form a zip archive, i.e., “CompressedFile.zip” archive.

How to Zip a Directory/Folder in Ubuntu 22.04 via Terminal?

A single Directory is compressed to a zip archive by launching the terminal and executing the zip command. For example, a directory “Screenshots” can be compressed to create a zipped archive “CompressedFolder.zip” by executing the following command:

$ zip -r CompressedFolder.zip Screenshots

The above command comprises of:

  • zip: tar command line tool
  • -r: flag for directory
  • CompressedFolder.zip: Name of compressed archive
  • Screenshots: Name of Directory to be compressed

From the above image, it can be seen that the directory “Screenshots” is compressed to a zip archive, i.e., “CompressedFolder.zip”.

How to Zip Multiple Directories in Ubuntu 22.04 via Terminal?

Zip” command is used to compress multiple directories via Terminal. For example, directories: Directory1, Directory2, and Directory3 can be compressed to create a zipped archive “CompressedFile.zip” by executing the following command:

$ zip -r CompressedFile.zip Directory1 Directory2 Directory3

The above command comprises of:

  • zip: tar command line tool
  • -r: flag for directory
  • CompressedFile.zip: Name of compressed archive
  • Directory1, Directory2, Directory 3: Name of Directories to be compressed

From the above image, it can be seen that the directories, Directory1, Directory2, and Directory3 are compressed to a zip archive, i.e., “CompressedFile.zip”.

How to Zip Files/Directories in Ubuntu 22.04 Using GUI?

Files and Directories are compressed with ease with just a few clicks using Linux/Ubuntu GUI. The following sections discuss creating Zip Archives from multiple files, and single and multiple directories:

How to Zip Files in Ubuntu 22.04 Using GUI?

Multiple Files can be compressed into a zip archive by selecting all files by either a keyboard or a mouse and then selecting “Compress” from the right-click drop-down menu:

This will redirect to the “Create Archive” window where we can insert the Archive name and select .zip format to compress the file in .zip format. Finally, we can press the Create button.

Then click on the Create button to create a zip archive file “CompressedFile.zip” from the selected files, i.e., File1, File2, File3, File4, and File5.

How to Zip a Directory/Folder in Ubuntu 22.04 Using GUI?

A directory can be compressed into a zip archive by selecting the directory with either a keyboard or a mouse and then selecting “Compress” from the right-click drop-down menu:

This will redirect to the “Create Archive” window where we can insert the Archive name and select .zip format to compress the file in .zip format. Finally, we can press the Create button.

Then click the Create button to create a zip archive file “CompressedFile.zip” from the selected directory, i.e., “Screenshots”.

How to Zip Multiple Directories/Folders in Ubuntu 22.04 Using GUI?

Multiple directories can be compressed into a zip archive by selecting the directories with either a keyboard or a mouse and then by selecting “Compress” from the right-click drop-down menu:

This will lead us to the “Create Archive” window where we can insert the Archive name and select the .zip format to compress the selected directories in .zip format.

Finally, click on the Create button to create a zip archive file “CompressedDirectory.zip” of the selected directories, i.e., Directory1, Directory2, and Directory3.

Conclusion

Files and Directories can be compressed to a zip archive with ease with the command line as well as GUI. Files can be compressed using “zip <archivename> <file1> <file2>”. Similarly, single and multiple directories can be compressed by using “zip -r <archivename> <Directory>” and “zip -r <archivename> <Directory1> <Directory2>”. This article has demonstrated the process of compressing files and directories using .zip archive format on Linux/Ubuntu 22.04 LTS by command line as well as by GUI.

Similar Posts