Unzip file linux terminal

Practical Examples of the Unzip Command in Linux

Got a zip file in the terminal? Learn how to use the unzip command in Linux with these practical examples.

If you have a zip compressed file, you can unzip it in the Linux command line. The unzip command in Linux is quite versatile and you can use it do a lot more than just extracting zip file.

I have discussed how to gzip a folder in Linux in the past. It’s time to see various usage of the unzip command. Before you do that, make sure that unzip has been installed on your system. You can use your distribution’s package manager to install the command.

On Ubuntu and Debian, you can use this command:

Once you have verified that, let’s see how to use unzip in Linux terminal.

Unzip command in Linux

The unzip command has a really simple syntax:

If you use it to extract a zip file without any option, it will extract all the files in the current directory:

unzip webdesign.zip Archive: webdesign.zip inflating: 339252-PAJF05-394.ai inflating: 339252-PAJF07-322.eps inflating: 339252-PALBTI-224.ai inflating: 339252-PALBTL-394.eps inflating: 339252-PALBTM-53.jpg inflating: License free.txt inflating: License premium.txt

And that’s not what you would want most of the time. It’ll just flood your current directory with all the extracted files.

ls 339252-PAJF05-394.ai 339252-PALBTI-224.ai 339252-PALBTM-53.jpg 'License premium.txt' 339252-PAJF07-322.eps 339252-PALBTL-394.eps 'License free.txt' webdesign.zip

1. 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 target_directory zip_file

If the target directory doesn’t exist, it will be created. You cannot create nested directories in this manner though.

Do note that you can also put the target directory at the end but not all options can be added at the end.

unzip zip_file -d target_directory

2. See the content of the zip file without extracting

If you want to see what the zip file contains, you son’t always have to extract it first. You can use the -l option and it will show the content of the zip file.

As you can see, it also shows the timestamp of the files and the actual size of the individual files in bytes.

[email protected]:$ unzip -l webdesign.zip Archive: webdesign.zip Length Date Time Name --------- ---------- ----- ---- 205358 2018-06-18 23:14 339252-PAJF05-394.ai 996906 2018-06-18 23:14 339252-PAJF07-322.eps 213968 2018-06-20 00:00 339252-PALBTI-224.ai 1005362 2018-06-20 00:00 339252-PALBTL-394.eps 305531 2018-06-20 00:00 339252-PALBTM-53.jpg 1462 2018-06-20 09:45 License free.txt 1116 2018-06-20 09:45 License premium.txt --------- ------- 2729703 7 files

If you want, you can get more information like the compressed size, compression ratio by using the verbose mode with -v option. The CRC-32 in the output is the cyclic redundancy check.

[email protected]:$ unzip -v webdesign.zip Archive: webdesign.zip Length Method Size Cmpr Date Time CRC-32 Name -------- ------ ------- ---- ---------- ----- -------- ---- 205358 Defl:N 142097 31% 2018-06-18 23:14 792f2380 339252-PAJF05-394.ai 996906 Defl:N 221228 78% 2018-06-18 23:14 440390d3 339252-PAJF07-322.eps 213968 Defl:N 147568 31% 2018-06-20 00:00 cdb64dfc 339252-PALBTI-224.ai 1005362 Defl:N 226727 77% 2018-06-20 00:00 aed3d97a 339252-PALBTL-394.eps 305531 Defl:N 183363 40% 2018-06-20 00:00 e4ced90f 339252-PALBTM-53.jpg 1462 Defl:N 728 50% 2018-06-20 09:45 0eb9e17b License free.txt 1116 Defl:N 558 50% 2018-06-20 09:45 165dd84e License premium.txt -------- ------- --- ------- 2729703 922269 66% 7 files

3. Overwrite all the files without prompting

If there are already files with the same name in the directory where you are extracting the files, you’ll be promoted for each such files. You can force overwrite all the files with option -o .

unzip -o -d target_directory zip_file

4. Do not overwrite any files -n

If you don’t want any existing file to be overwritten by newly extracted files, use the -n option (stands for never overwrite).

unzip -n -d target_directory zip_file

5. Update files and create if necessary

This is slightly different the overwriting all the files. In this case, only those files will will be overwritten that have newer timestamp than the existing files. If a file doesn’t exist, it will be created.

Читайте также:  Canon canoscan 4200f linux

You can achieve that with option -u:

unzip -u -d target_directory zip_file

6. Freshen existing files but create none

Slight change from the previous example here. In this one, it will update the existing files if they have older timestamp but it won’t create any new files even if they don’ exist.

The option -f allows you to do that:

unzip -f -d target_directory zip_file

7. Extract in quiet mode

When you unzip a file, it shows all the files that have been extracted on the display. Now imagine a zip file that has hundreds of files in it. If you extract it, your screen will be cluttered with the output.

You can use the quiet mode with option -q and you won’t see anything on the display:

unzip -q -d target_directory zip_file

8. Exclude files from extraction

You can also exclude certain files or certain type of files from being extracted.

unzip zip_file -x file_to_exclude

In my example, let’s say I don’t want to extract any .eps files.

[email protected]:$ unzip webdesign.zip -x *.eps Archive: webdesign.zip inflating: 339252-PAJF05-394.ai inflating: 339252-PALBTI-224.ai inflating: 339252-PALBTM-53.jpg inflating: License free.txt inflating: License premium.txt

Those were some of the most common examples of the unzip command in Linux. You can always check its man page to learn about more options.

Do you use some other option with unzip frequently? Why not share it with us in the comments?

Источник

How To Unzip Files in Linux (4 Methods)

Ever found yourself in a situation where you’ve downloaded a zipped file on your Linux system and you’re scratching your head, wondering how to set the contents free? Fear not, brave adventurer! This guide will equip you with not one, not two, but five different ways to unzip files in Linux. By the end of it, you’ll be unzipping files faster than a kangaroo on a trampoline!

Читайте также:  Can you replace windows with linux

We are focusing on the Ubuntu variant in this how to guide however these methods will work with most linux distributions.

Table of Contents

How To Unzip Files Using File Roller

For those who prefer to point and click rather than type, the File Roller (or Archive Manager) is your trusty steed.

  1. Navigate to your zipped file using the file explorer. Navigate to file
  2. Right-click on the file and select ‘Open With Archive Manager’. Open with Archive Manager
  3. Click ‘Extract’. It’s like clicking ‘Open Sesame’ on a treasure chest. Click Extract

How To Unzip Files Using Terminal

Ah, the classic unzip command. It’s like the Swiss Army Knife of unzipping files—always handy, and always gets the job done.

  1. First, you need to open a terminal. Press Ctrl + Alt + T to pop one open. It’s like summoning a genie but for commands. Open Terminal
  2. Navigate to the directory with the zipped file. For example, if your file is in the Downloads directory, type: cd Downloads Navigate to Directory
  3. Now, simply type unzip followed by the zip file name., replacing filename.zip with the name of your file. unzip filename.zip Unzip FileAnd voila! Your file is as free as a bird ! To get a full list of options, just enter unzip on it’s own with no extra options or parameters. Unzip options

How To Unzip Files Using Firefox

Another method that requires no new software is to use firefox browser and our very own ezyZip online unzipper.

  1. Navigate to the zip extractor page on ezyZip.
  2. Select the file zip file you wish to extract. Navigate to ezyZip
  3. Click on the green “Save” button to save files to your desired folder. Select FileRead the full zip extraction instructions on the page itself.

How To Unzip Files Using 7-Zip

Meet 7-Zip, the Hercules of file compression tools. You’ll need to install it first, though.

  1. First, you need to install 7-Zip. We like the p7zip desktop GUI. Use the following command to install it: sudo snap install p7zip-desktop install p7zip-desktop
  2. Search and open “P7Zip Desktop”. open p7zip desktop
  3. Navigate to the file you wish to extract and click on “Extract” Navigate to Directory
  4. Select your destination folder and click “OK”. Extract FileThat’s all there is to it!

About The Author

Ezriah Zippernowsky

With Ezriah’s expertise, navigating the intricacies of file compression and understanding the functionalities of archiving becomes a breeze. From crafting step-by-step tutorials to creating in-depth videos, Ezriah brings complex technical concepts to life, making them accessible to users of all levels of expertise. Ezriah represents the collective wisdom of the entire ezyZip team.

Источник

How to Unzip a Zip File in Linux [Beginner’s Tutorial]

This quick tip shows you how to unzip a file in Ubuntu and other Linux distributions. Both terminal and GUI methods have been discussed.

Zip is one of the most common and most popular ways to create compressed archive files. It is also one of the older archive file formats that were created in 1989. Since it is widely used, you’ll regularly come across a zip file. In an earlier tutorial, I showed how to zip a folder in Linux. In this quick tutorial for beginners, I’ll show you how to unzip files in Linux. Prerequisite: Verify if you have unzip installed In order to unzip a zip archive file, you must have the unzip package installed in your system. Most modern Linux distributions come with unzip support but there is no harm in verifying it to avoid bad surprises later. In a terminal, use the following command:

Читайте также:  Linux настройка web камеры

If it gives you some details, you have unzip installed already. If you see an ‘unzip command not found’ error, you have to install. In Ubuntu and Debian based distributions, you can use the command below to install unzip.

Unzip files in Linux command line

Using unzip command in Linux is absolutely simple. In the directory, where you have the zip file, use this command:

You can also provide the path to the zip file instead of going to the directory. You’ll see extracted files in the output:

unzip metallic-container.zip -d my_zip Archive: metallic-container.zip inflating: my_zip/625993-PNZP34-678.jpg inflating: my_zip/License free.txt inflating: my_zip/License premium.txt

There is a slight problem with the above command. It will extract all the contents of the zip file in the current directory. That’s not a pretty thing to do because you’ll have a handful of files leaving the current directory unorganized.

Unzip to a specific directory

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.

unzip zipped_file.zip -d unzipped_directory

Now all the contents of the zipped_file.zip will be extracted to unzipped_directory.

Since we are discussing good practices, another tip you can use is to have a look at the content of the zip file without actually extracting it.

See the content of the zip file without unzipping it

You can check the content of the zip file without even extracting it with the option -l.

unzip -l metallic-container.zip Archive: metallic-container.zip Length Date Time Name --------- ---------- ----- ---- 6576010 2019-03-07 10:30 625993-PNZP34-678.jpg 1462 2019-03-07 13:39 License free.txt 1116 2019-03-07 13:39 License premium.txt --------- ------- 6578588 3 files

There are many other usage of the unzip command in Linux but I guess now you have enough knowledge to unzip files in Linux.

Unzip files in Linux using GUI

You don’t always have to go to the terminal if you are using desktop Linux. Let’s see how to unzip in Ubuntu Linux graphically. I am using GNOME desktop here with Ubuntu 18.04 but the process is pretty much the same in other desktop Linux distributions.

Open the file manager and go to the folder where your zip file is stored. Right click the file and you’ll see the option “extract here”. Select this one.

Unzip Files Ubuntu

Unlike the unzip command, the extract here options create a folder of the same name as the zipped file and all the content of the zipped files are extracted to this newly created folder. I am glad that this is the default behavior instead of extracting everything in the current directory.

There is also the option of ‘extract to’ and with that you can specify the folder where you want to extract the files.

That’s it. Now you know how to unzip a file in Linux. Perhaps you might also be interested in learning about using 7zip in Linux.

If you have questions or suggestions, do let me know in the comment section.

Источник

Оцените статью
Adblock
detector