Friday, 16 February 2018

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

LPI Tutorials and Materials, LPI Guides, LPI Certifications, LPI Learning

You can use the unzip or tar command to extract (unzip) the file on Linux or Unix-like operating system. Unzip is a program to unpack, list, test, and compressed (extract) files and it may not be installed by default.

Use tar command to unzip a zip file

The syntax is:

tar xvf {file.zip}
tar -xvf {file.zip}

Use the following syntax if you want to extract/unzip to a particular destination directory:

tar xvf {file.zip} -C /dest/directory/
tar -xvf {file.zip} -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:

LPI Tutorials and Materials, LPI Guides, LPI Certifications, LPI Learning

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

Use unzip command to unzip a zip file

The syntax is:

unzip {file.zip}

Use the following syntax if you want to extract/unzip to a particular destination directory:

unzip -d /dest/directory/ {file.zip}

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:

LPI Tutorials and Materials, LPI Guides, LPI Certifications, LPI Learning

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.

Install 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

Install unzip on CentOS/RHEL/Scientific/Oracle Linux


Use the yum command to install unzip command:

yum install unzip

Install unzip on Fedora Linux


Use the dnf command to install unzip command:

dnf install unzip

Install unzip on Suse/OpenSUSE Linux


Use the dnf command to install unzip command:

zypper install unzip

Install unzip on FreeBSD unix


To install the unzip port, run:

# cd /usr/ports/archivers/unzip/ && make install clean

To add the package rung pkg command:

# pkg install unzip

Install unzip on OpenBSD unix


Type the following pkg_add command to install unzip package:

# pkg_add -v unzip

Related Posts

0 comments:

Post a Comment