- Example 1: Extracting tar Files to a Specific Directory. In the first example, I will extract the files in articles.tar to a directory /tmp/myarticle. Always make sure that the directory into which you want to extract tar file exists. Let me start by creating the /tmp/myarticle directory using the command below: # mkdir /tmp/myarticle.
- Install zip & unzip command on CentOS / RHEL / Fedora. Open the terminal and execute the beneath command, $ sudo yum install -y zip unzip or $ sudo dnf install -y zip unzip. Let’s dive in and see how to zip and unzip files and directories in Linux with zip and unzip command with examples. Zip command in Linux. Zipping a file is as easy as ABC.
Unzip to a directory The expected behavior is that you should have the files extracted to a certain directory, normally with the same name as the zip file. You can specify the target directory where you want to extract the files. Unzip -d targetdirectory zipfile.
In this tutorial we will explain how to zip and unzip files in Linux systems through the command line using the zip and unzip command.
Above all, ZIP is the most widely used archive file format that supports lossless data compression. A ZIP file is a data container containing one or more compressed files or directories.
Compressing several files and folders into a single distributable file is the most common way done by many computer users around the world. In Windows, you can simply use Winzip, WinRAR, 7Zip, and so on to zipping and unzipping file. How to send music from android. If you’ve installed full Linux distros with GUI, you can also find and use similar app to do similar tasks. But what about a Linux server which you can only access it via SSH client?
Installing zip and unzip
On RedHat/CentOS based system:
On Ubuntu/Debian based system:
![How to unzip a file How to unzip a file](https://kinsta.com/wp-content/uploads/2020/04/ssh-terminal-list-files.jpg)
How to create a ZIP file with the zip command
To create a ZIP file, you need to tell zip the name of the archive file and which files to include in it. To test this, we created two files: file-01.txt and file-02.txt. We will compress them into my-archive.zip with the following command:
As a result, each file is listed as it’s added. The name of the file and the amount of compression that was achieved on that file is shown also.
In addition, if you do not want to see the output from zip as the ZIP file is created, use the -q (quiet) option.
To include sub-directories and everything contained in them in the ZIP file, use the -r (recursive) option and include the name of the sub-directory on the command line.
Adding passwords to ZIP files is easy. For example, you can use the -e (encrypt) option and you’ll be prompted to enter your password and to re-enter it for verification.
You can add or update one or more files of the compressed archive. Suppose we have compressed an archive then, modified a file. There is a possibility to add the update file to the compressed archive with the -u (update) option.
How to unzip a ZIP file with the zip command
Using unzip command in Linux is absolutely simple. How to take a moving screenshot. For example, in the directory, where you have the zip file, use this command:
Just like zip, unzip has a -q (quiet) option, so that you do not need to see the file listing as the files are extracted.
In addition, a good practice is to unzip to directory in Linux command line. This way, all the extracted files are stored in the directory you specified. If the directory doesn’t exist, it will create one.
Ubuntu Unzip To Directory
You can check the content of the zip file without even extracting it with the -l option.
Unzip To Directory Terminal File
In conclusion, in this article, we have explained how to compress/zip and extract/unzip .zip archive files in Linux terminal. Of course, you can add your thoughts to this article via the feedback form below.