Unzipping in linux terminal

How to unzip a zip file using the Linux and Unix bash shell terminal

Use unzip command to unzip a zip file

The syntax is:
unzip
Use the following syntax if you want to extract/unzip to a particular destination directory:
unzip -d /dest/directory/
For example, unzip a zip file named master.zip using zip command:
unzip master.zip
To unzip a zip file named master.zip using zip command to a /tmp/data/ directory:
unzip -d /tmp/data/ master.zip
Sample session:

Fig.02: How to unzip a zip file from the Terminal using unzip command

A note about bash: unzip: command not found

If the unzip command NOT installed on your Linux or Unix box, then run any one of the following commands as per your Linux distribution to install the unzip command.

Make sure you run the following command as the root user. For instance:
sudo command
OR
su —

Installing unzip on Debian/Ubuntu Linux

Use the apt-get command or apt command to install unzip command:
sudo apt-get install unzip
OR
sudo apt install unzip

Install unzip on Arch Linux

Use the pacman command to install unzip command:
pacman -S unzip

CentOS/RHEL/Scientific/Oracle Linux install unzip command

Use the yum command or dnf command to install unzip command:
yum install unzip

  • No ads and tracking
  • In-depth guides for developers and sysadmins at Opensourceflare✨
  • Join my Patreon to support independent content creators and start reading latest guides:
    • How to set up Redis sentinel cluster on Ubuntu or Debian Linux
    • How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
    • How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
    • A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
    • How to protect Linux against rogue USB devices using USBGuard

Join Patreon

Fedora Linux install unzip

Use the dnf command to install unzip command:
dnf install unzip

Installing unzip on Suse/OpenSUSE Linux

Use the zypper command to install unzip command:
zypper install unzip

FreeBSD Unix install unzip

To install the unzip port, run:
# cd /usr/ports/archivers/unzip/ && make install clean
To add the package rung pkg command:
# pkg install unzip

OpenBSD Unix install unzip

macOS Unix install unzip CLI

Let us install Homebrew on macOS. Once installed type the following brew command to install unzip utility:
$ brew install unzip

Use tar command to unzip a zip file

The syntax is:
tar xvf
tar -xvf
Use the following syntax if you want to extract/unzip to a particular destination directory:
tar xvf -C /dest/directory/
tar -xvf -C /dest/directory/
For example, unzip a zip file named master.zip using tar command:
tar xvf master.zip
To unzip a zip file named master.zip using tar command to a /tmp/data/ directory:
tar xvf master.zip -C /tmp/data/
ls -l /tmp/data/
cd /tmp/data/
ls -l
Sample session:

Читайте также:  Linux подключение мегафон модем

Fig.01: How to use a tar command to unzip a file on Linux/Unix-like terminal

🐧 Get the latest tutorials on Linux, Open Source & DevOps via

Category List of Unix and Linux commands
Documentation help • mandb • man • pinfo
Disk space analyzers df • duf • ncdu • pydf
File Management cat • cp • less • mkdir • more • tree
Firewall Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04
Linux Desktop Apps Skype • Spotify • VLC 3
Modern utilities bat • exa
Network Utilities NetHogs • dig • host • ip • nmap
OpenVPN CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04
Package Manager apk • apt
Processes Management bg • chroot • cron • disown • fg • glances • gtop • jobs • killall • kill • pidof • pstree • pwdx • time • vtop
Searching ag • grep • whereis • which
Shell builtins compgen • echo • printf
Text processing cut • rev
User Information groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w
WireGuard VPN Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04

Comments on this entry are closed.

I’d just like to interject for a moment. What you’re referring to as Linux, is in fact, GNU/Linux, or as I’ve recently taken to calling it, GNU plus Linux. Linux is not an operating system unto itself, but rather another free component of a fully functioning GNU system made useful by the GNU corelibs, shell utilities and vital system components comprising a full OS as defined by POSIX.

Many computer users run a modified version of the GNU system every day, without realizing it. Through a peculiar turn of events, the version of GNU which is widely used today is often called “Linux”, and many of its users are not aware that it is basically the GNU system, developed by the GNU Project.

There really is a Linux, and these people are using it, but it is just a part of the system they use. Linux is the kernel: the program in the system that allocates the machine’s resources to the other programs that you run. The kernel is an essential part of an operating system, but useless by itself; it can only function in the context of a complete operating system. Linux is normally used in combination with the GNU operating system: the whole system is basically GNU with Linux added, or GNU/Linux. All the so-called “Linux” distributions are really distributions of GNU/Linux.

unzip worked for a zip file, tar xvf did not work for me…

error:
tar: This does not look like a tar archive
tar: Skipping to next header
tar: Exiting with failure status due to previous errors

You cannot use tar to extract a zip file. I demand that you fix this web page.

Источник

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

Last updated October 9, 2019 By Abhishek Prakash 9 Comments

Brief: 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 way to create compressed archive files. It is also one of the older archive file format that was 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 beginner’s, 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 uzip support but there is no harm in verifying it to avoid bad surprises later.

In Ubuntu and Debian based distributions, you can use the command below to install unzip. If it’s already installed, you’ll be notified about it.

Once you have made sure that your system has unzip support, it’s time to unzip a zip file in Linux.

You can use both command line and GUI for this purpose and I’ll show you both methods.

Unzip file 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:

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 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.

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 zip file without unzipping it

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

Here’s a sample output:

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.

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.

Like what you read? Please share it with others.

Источник

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

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

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

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

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 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

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.


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

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

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

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.

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

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

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.

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

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

-C, —directory DIR – change to directory DIR

Источник

Читайте также:  Как почистить mac os catalina
Оцените статью