Unzip files in linux terminal

How to unzip a zip file using Terminal in Linux (Ubuntu, Linux mint, Debian …)?

In this post I am going to show you how to unzip the .zip file which you have download from the internet or got it from some means. This can be achieved in many different ways, but we will see how to use terminal to unzip the file.

Install unzip

So First of all we need to install unzip on our system if it’s not installed.
unzip command is used to extract files from a ZIP archive.
Run the following command to install unzip

sudo apt-get install unzip
$ unzip [-aCcfjLlnopqtuvy] [-d dir] zipfile

Now Follow the steps below:

UnZip File

OPTION 1 – If the Zip File is in the same directory/folder in which your terminal is and we want to extract it in the present working directory.
Use the following command to achieve the above described scenario

sudo unzip zip_file_name.zip

if the zip file is protected with some password, then use the following command :

sudo ubzip -P zip_file_name.zip

Please make sure you use -P (capital P) not -p because the are different options.

OPTION 2 –
If the zip file is not present in the same directory and we want to extract/unzip the file in different directory.
Use the following command to achieve the above described scenario

sudo unzip path/filename.zip -d another_path_or_same_path

if we does not use option -d the file will be extracted to present working directory.

And if the zip file is password protected we can also use -P .

use tar Command in Linux / Unix

tar Command in Linux Unix

tar is an acronym for Tape Archive. tar command is used to Manipulates archives in Linux/Unix. System administrators uses tar command frequently to rip a bunch of files or directories into highly compressed archive which are called tarball or tar , bzip and gzip in Linux/Unix system.

tar Syntex

Or
tar required Flags

tar optional Flags

tar [ -d ][-B] [ -F ] [ -E ] [ -i ] [-h ] [ -l ] [ -m ] [ -o ] [ -p ] [ -w] [ -s ] [ -U ] [ -v ] [-Number] [-b Blocks] [-f Archive]

Examples

Create tar Archive File by Compressing an Directory or a Single File

The terminal command below will create a .tar file called sample_dir.tar with a directory /home/codebind/sample_dir or sample_dir in present working directory.

codebind@codebind:~$ tar -cvf sample_dir.tar sample_dir sample_dir/ sample_dir/main.cpp sample_dir/sample.png sample_dir/output codebind@codebind:~$ ls sample_dir sample_dir.tar

Create tar Archive File

Here’s what those flags (-cvf) actually mean
-c, —create – create a new archive
-x, —extract, —get – extract files from an archive
-f, —file ARCHIVE – use archive file or device ARCHIVE

Читайте также:  Linux вывести только первую строку

Create tar.gz or tgz Archive File by Compressing an Directory or a Single File

The terminal command below will create a .tar.gz file called sample_dir.tar.gz with a directory /home/codebind/sample_dir or sample_dir in present working directory.

Notice that we have added extra flag -z to the command.Here’s what the flag -z actually mean
-z, —gzip, —gunzip —ungzip – Compress the archive with gzip

codebind@codebind:~$ tar -cvzf sample_dir.tar.gz sample_dirsample_dir/ sample_dir/main.cpp sample_dir/sample.png sample_dir/output codebind@codebind:~$ ls sample_dir sample_dir.tar.gz

Create tar.gz Archive

The command bellow will create a .tgz file. One this to notice is tar.gz and tgz both are similar.

codebind@codebind:~$ tar -cvzf sample_dir.tgz sample_dirsample_dir/ sample_dir/main.cpp sample_dir/sample.png sample_dir/output codebind@codebind:~$ ls sample_dir sample_dir.tgz

Compressing Multiple Directories or Files at Once

Let’s say, For example we want to compress the sample_dir directory, the java_test directory, and the abc.py file to a tar file called sample_dir.tar.gz.
Run the following command to achieve the goal above.

codebind@codebind:~$ tar -cvzf sample_dir.tar.gz sample_dir java_test abc.py sample_dir/ sample_dir/main.cpp sample_dir/sample.png sample_dir/output java_test/ java_test/HelloCV.java abc.py codebind@codebind:~$ ls sample_dir java_test abc.py sample_dir.tar.gz

Compressing Multiple Directories or Files at Once

Create .bzip2 Archive File by Compressing an Directory or a Single File

codebind@codebind:~$ tar -cjvf sample_dir.tar.bz2 sample_dir sample_dir/ sample_dir/main.cpp sample_dir/sample.png sample_dir/output codebind@codebind:~$

Notice that we have added extra flag -f to the command.Here’s what the flag -f actually mean

-f, —file ARCHIVE – use archive file or device ARCHIVE

Use bzip2 Compression

Extract .tar Archive File

We can extract or untar the compressed file using the tar command. The command below will extract the contents of sample_dir.tar to the present directory.

codebind@codebind:~$ tar -xvf sample_dir.tar sample_dir/ sample_dir/main.cpp sample_dir/sample.png sample_dir/output codebind@codebind:~$

Extract .tar Archive File

The following command will extract or Untar files in specified Directory i.e. /home/codebind/dir_name in this case.

codebind@codebind:~$ tar -xvf sample_dir.tar -C /home/codebind/dir_name sample_dir/ sample_dir/main.cpp sample_dir/sample.png sample_dir/output codebind@codebind:~$

we have added extra flag -C to the command.Here’s what the flag -C actually mean

-C, —directory DIR – change to directory DIR

Источник

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!

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
Читайте также:  Backing up linux systems

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:

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.

Читайте также:  Как добавить свою команду в linux

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