If you are using Linux Ubuntu 22.04 system, and you have to compress or extract any files, or directories, use zip -r archive_name files_to_be_zip command to create a zip file and unzip archive_name command to unzip the file.
Here are two methods to zip or compress and unzip or extract files and directories with and without password protected on ubuntu 22.04 Linux terminal:
- Method 1: Zip or Compress Files And Directories Ubuntu Linux Command Line
- Method 2: Extract or Unzip Files And Directories Ubuntu Linux Command Line
Method 1: Zip or Compress Files And Directories Ubuntu Linux Command Line
zip
is not installed by default in most Linux distributions. To install it, you need to type this command in the terminal and hit Enter according to your os:
//For Ubuntu and Debian:
sudo apt install zip
//For CentOS and Fedora:
sudo yum install zip
Now let us see how to compress a file or directory and create a zip file, here are some examples:
Create a Zip File
To create a zip by compressing a file, you can use this command on linux ubuntu command line:
zip filename
Create a Zip Folder
To create a folder zip by compressing a folder, you can use the command:
zip directory_name
Zip Multiple Files at Once
To create a zip of multiple files at once, you can use this command on an Ubuntu Linux terminal:
zip archivename.zip filename1 filename2 filename3
Zip Multiple Folders at Once
To create a zip of multiple directories or folders at once, you can use this command on an Ubuntu Linux terminal:
zip -r archivename.zip directory_name1 directory_name2 file1 file1
Create a Password Protected ZIP File, Directory
To create a password-protect zip file, you can use this command on the Ubuntu Linux command line:
zip -e archivename.zip filename
To create a password-protect zip directory, you can use this command on the Ubuntu Linux command line:
zip -e archivename.zip directory_name
The command will be prompted to enter and verify the archive password:
Enter password: Verify password:
Method 2: Extract or Unzip Files And Directories Ubuntu Command Line
unzip
is not installed by default in most Linux distributions. So, you can easily install it using the following commands according to your OS:
//For Ubuntu and Debian
sudo apt install unzip
//For CentOS and Fedora:
sudo yum install unzip
Now let us see how to extract, or unzip archive files or directories on command line or terminal, here are some examples:
Unzip a Zip File Command Line
If you want to unzip a single zip archive file on an Ubuntu Linux terminal, you can use the command:
unzip filename
Unzip a Directory
If you want to extract a single folder zip archive to an Ubuntu Linux terminal, you can use this command:
unzip directory_name
Extract Multiple Zip Files at Once
To unzip multiple zip files on Linux Ubuntu command line, you need to use the command:
unzip archivename.zip filename1 filename2 filename3
Extract Multiple Zip Directory at Once
Now let’s see how to unzip or extract multiple zip directories, and files at once, you can use this command:
An alternate way to unzip multiple files and directories in linux using command line. You can use regular expressions, as shown below:
unzip '*.zip'
zip -r archivename.zip directory_name1 directory_name2 file1 file1
Unzip File to a Specific Directory
To unzip a zip file, or directory to a different directory location, you can use this command on Linux ubuntu terminal,:
unzip filename.zip -d /path/to/directory
Extract Password Protected Zip File, Directory
If any file zip, or directory is password protected, and you want to unzip or extract it, you can use the command on Linux Ubuntu terminal:
unzip -P PasswOrd filename.zip
unzip filename.zip -d /path/to/directory
Here is the video guide on How to Zip and Unzip Files on Ubuntu 22.04 Linux Terminal:
Conclusion
That’s it; In this tutorial, you have learned how to create a zip and extract or unzip files and directories on Ubuntu Linux terminal.
Thank you, I’m a novice in Linux, it was really helpful!