Being the default compression utility in Windows, and quite widely used, you probably wonder how to use this utility in CentOS 7.
Well, in CentOS 7 in order to zip and unzip files and folders, we will use the unzip package, and it might not be installed by default but we’ll go over that too.
This guide will focus only on working from the terminal as I feed that the graphical interface is quite self-explanatory and if you worked with a zip archive on windows or other Linux distros, you’ll be able to work on CentOS 7 too.
How to install unzip on CentOS 7?
As I said, the unzip package might not be installed by default, but fortunately, it’s available in the official package repository of CentOS 7. So the installing part will be easy.
Update the YUM package repository cache using the following command:
sudo yum makecache
Now install unzip using:
sudo yum install unzip
Press y and then <Enter> to confirm and unzip should be installed.
To check if it works or what version of unzip you run, use the following command:
And a bunch of details regarding your current version of unzip should show up. All good.
How to show the contents of a zip file using unzip?
You can see every file and folder (or directory) stored inside a Zip file/archive using the following command:
unzip -l filename.zip
How to extract a zip file using unzip?
In order to extract the contents of a Zip file into the current working directory where the zip file is, run this:
If you want to extract it to another directory, under the current working directory you will need to enter something like this:
unzip app.zip -d ~/CurrentFolder/AnotherFolder
This will extract the files from the app.zip file inside the AnotherFolder folder. Replace file and directory with your own of course.
And to check if the files were successfully, just do this command, that will output the files inside the respective directory:
How to extract just one file from zip file using unzip in Centos 7?
Let’s say your zip file contains a lot of files but you just need one of them extracted. Easy and fast. Let’s say the file is file.css.
unzip app.zip file.css
The above will extract just file.css to the current working directory.
Of course, you can also extract just a file, to another directory like this:
unzip app.zip file.css -d ~/CurrentFolder/AnotherFolder
The above will extract our file to the AnotherFolder folder.
Please note that if you want to extract a specific subdirectory from the Zip file, you need to do something like this:
Let’s assume our Zip file contains a ‘web’ directory amongst other things inside of it.
unzip app.zip 'web/*' -d ~/CurrentFolder/AnotherFolder
This will extract our web subdirectory from within the Zip file, into the AnotherFolder folder.
So that’s how you can work with Unzip in Centos 7 really fast. It’s handy to know these things, or just keep the commands close until you learn them by heart.
Tech jack of all trades. Programmer, sysadmin and a general tech enthusiast. I work with a lot of stuff, and love learning and talking about new or interesting stuff.