How to Unzip Files in Linux Terminal


One of the many file-related tools included in Linux, a popular operating system, is the ability to zip and unzip files. As archived files are collections of one or more files or pieces of information, there are several methods for archiving and recovering files in Ubuntu.

An “archive file” is a file that merges many data files into a single file, compresses the contents to save storage space, and facilitates simple file transfers between computers. Some of the most common methods that you can implement to unzip files using a Linux terminal are mentioned below:

Using unzip Command

The unzip command is one of the most popular ways to extract data from archived files using a terminal on Linux and you can install it by writing the following command in the terminal.

$ sudo apt install unzip 

Unzip-Files-Linux-Terminal

Syntax:

The basic syntax of this command that you need to understand for its operation is mentioned below:

$ unzip filename.zip

For example, if you want to unzip any file then you need to write unzip followed by that file name as shown below:

$ unzip linux1.zip

Unzip-Files-Linux-Terminal

Output:

Check whether the file is extracted by listing the all files in a directory.

Unzip-Files-Linux-Terminal

Using tar Command

Another common method to extract data from archived files using a terminal in Linux is by using tar command. It comes pre-installed in Ubuntu which stands for “tap archive “used to compress, extract the compressed files, and maintain and modify them. The files zipped with “.tar” extension are unzipped by tar command.

Syntax:

$ tar [options] filename.tar

Some options with tar command are:

Options:

-c : it create compressed files
-x : it extracts the compressed files
-f : creates compressed file with given filename
-t : displays or lists files in zip file
-u : compresses and adds to an existing zip file
-v : output verbose information
-A : concatenate the zip files
-z : zip, tells tar command that creates tar file using gzip
-j : filter archive tar file using tbzip
-W : verifies compressed file
-r : updates or add file/files or directory in already existed .tar file

Below mentioned command will unzip “linux2.tar” by tar command:

$ tar xvf linux2.tar

Unzip-Files-Linux-Terminal

Output:

Check whether the file is extracted by listing the all files in directory

Unzip-Files-Linux-Terminal

Unzip File using gunzip command

The gunzip command, which is also pre-installed, is another popular method for extracting data from archived files via a terminal under Linux. The gunzip command on Linux shrinks or enlarges a file or files and then overwrites the archived file(s) with the original file(s). The file(s) will restore its original extension upon extraction.

Syntax:

$ gunzip filename.gz

Unzip-Files-Linux-Terminal

Below mentioned command will unzip “linux3.txt.gz” by gunzip command

$ gunzip linux3.txt.gz

Output:

Check whether the file is extracted by listing the all files in a directory

Unzip-Files-Linux-Terminal

Conclusion:

Every operating system can compress a file or directory using a variety of techniques to free up storage space and make file transfers simpler. A file known as an “archive file” unifies several data files into one, compresses the data inside to conserve storage space, and simplifies file transfers between computers.

We have discussed different ways in this article that you can use to unzip files in Linux via a terminal.

Print Friendly, PDF & Email
Categories