How to zip a Folder in Ubuntu Linux


In Ubuntu (or any other OS), zipping a folder refers to compressing folder(s) and its data into a single archive. The zip technique is used to better organize and secure the data. It helps in the smooth transfer of multiple files in a single file/folder. Not only on Linux, zip is also supported on other platforms (Windows and Mac), which makes it favorable among the users.

Keeping its importance in view, this post addresses the methods to zip a folder in Ubuntu Linux:

Outline:

How to zip a Folder in Ubuntu Linux

As Ubuntu is considered the most loved Linux distribution for the Nube users. Being a Linux distribution, Ubuntu not only offers strong command line support but also has the Nautilus File Manager to ZIP a single as well as multiple folders. First, we will start with the zip command:

zip Command

The ZIP command allows you to compress the data in the “.zip” format. It offers single as well as multi-folder compression. Let’s understand the basic workings of the “zip” command using its syntax:

zip [options] <Path-to-store-ZIP-file> <Path-of-folder-to-be-Zipped>

For a detailed demonstration, get the “–help” option of the ZIP command and you will get the syntax and the supported options:

Let’s understand the zip command’s working via examples:

Example 1: ZIP a Single Folder

To zip a single folder, use the zip keyword with the zip name (to be created) and the folder to be zipped:

zip LinuxGenie.zip Genie
ls

The “ls” command is just used for run time verification:

  • Use the “-r” flag to zip the folder recursively (it considers the folders inside a folder being zipped) and shows the progress of the zipping process:
zip -r LGenie.zip Genie

  • Use the “-m” option to move the empty folder into a zip file. Moreover, use “-m” and “-r” combined to move the non-empty directory to the already created zip file:
zip -m LGenie.zip Music
zip -mr LGenie.zip Genie

  • You can use the “-e” flag to create an encrypted ZIP folder (it asks for a password at the time). Also, Use the “r” flag to include the files/sub-folders of the main folder. On the first prompt, it will ask you to set the password first, and then the zipping process proceeds:
zip -er legality.zip legal

If you unzip the protected folder using the unzip command, you will be asked to enter the password before extraction. Here’s the demonstration:

unzip legality.zip

For other zip methods, you can read the manual of the command or the help page:

Example 2: ZIP Multiple Folders/Directories

The “zip” command with the “r” flag zips the directories recursively. Any data inside the directories will also be zipped:

zip -r genie.zip dux legal returns

We have experimented with these commands in the current directory. However, you can use the zip command and ZIP folders placed at any location on the PC. You just have to use the complete path of the ZIP file to be created and the folders to be zipped.

File Manager | GUI

Ubuntu is equipped with the Nautilus file manager. It offers an interactive way to process all the command line operations. Let’s quickly understand how you can zip single as well as multiple folders using the GUI of Ubuntu:

Example 1: Zip a Single Folder

Navigate to your folder’s location (whose zip is to be created). Right-click on it and select “Compress” from the dropdown list:

A dialogue box opens:

  • 1: Choose the file/folder name.
  • 2: Also choose the “.zip” extension.
  • 3: Finally, click on “Create” to create the archive.

Moreover, to create a password-protected zip file, choose the password-protected zip option from the dropdown list:

A password field will appear, choose the strong password and click on “create”:

That’s how you can create a ZIP folder using GUI.

  • Zip Multiple Folders

Select multiple folders and right-click to choose the “Compress” option

Choose the Archive name and the zip type (either protected or simple). When all is done, click on “Create” to zip multiple folders:

That’s how you can ZIP single/multiple folder(s) in Ubuntu.

Bonus: How to Unzip a Folder in Ubuntu Linux

Like the zip command zips the folders, the unzip command is used to unzip the zipped folder. The unzip utility is available with the complete installation of Ubuntu. However, if it is not available, you can install it using the command:

sudo apt install unzip

The syntax of the unzip command is:

unzip <unzip-File> #To unzip in the current directory
unzip <unzip-File> -d <Destination-Folder> #Unzip in any other directory

For detailed usage of the unzip command, look at the supported options:

Example 1: Unzip a Single Folder

The command below unzip a folder named “genie.zip” in the current directory:

unzip genie.zip

If you want to get the result in some other directory, you can add the path of the destination directory. For instance, the command below unzips the “genie” folder into the “/home/adnan/extract”:

unzip genie.zip -d /home/adnan/extract

Example 2: Unzip Multiple Folders

To unzip multiple folders, either use the for loop or the wild card character. Although, both methods use the “wild card”. However, they differ in their basic functionality. Let’s exercise both:

  • For Loop

The following for loop select all the “.zip” files and store them in “f”. Then, the unzip command is applied to each value of “f”:

for f in *.zip; do unzip "$f"; done

  • Wild Card Character

Moreover, you can use the wild card character with a for loop to select and unzip multiple zip files/folders. For instance, the below command unzips the multiple folders in the current directory:

unzip '*.zip'

The first two examples refer to the CLI. Let’s dig into the GUI method of unzipping.

Example 3: Unzip Folders Using GUI

Navigate to the location where the ZIP folder is available. Here, either you have to extract in the same or some other directory.

  • Extract in the same directory: Right-click on it and choose “Extract Here”:

  • Extract to Some Other Directory: To extract to some other directory, Right click and choose “Extract to”.

Now, a new window opens. Select the directory where you want to unzip the folder:

That’s how you can unzip the folders in Ubuntu.

Bottom Line

Ubuntu has the zip command to zip single and multiple folders from the command line. Moreover, the File Manager of Ubuntu is quite effective in doing the same using GUI. The zip command offers more control over creating and managing the zip files. However, the GUI method is easy for users who are newly switched to Ubuntu.

All in all, this post has addressed the methods to zip as well as unzip folders in Ubuntu Linux.

Print Friendly, PDF & Email
Categories