How to Unpack Files in Linux Terminal

Linux is a popular operating system that includes various utilities for handling files, including zipping and unzipping files. Some other zip operations are zipcloak, zipdetails, zipsplit and zipinfo, but in this article, we will discuss how to extract data from files (unzip operation). In this article, I have used Ubuntu 22.04, a widely used and popular Linux distribution.

In Ubuntu, there are numerous techniques to archive files and retrieve archived files, because these files are collections of one or more files or information. The term “archive file” refers to a file that combines many data files into a single file, saving disk space on the computer by compressing the files and making it easier to transfer files from one computer to another. In most operating systems, including Linux, working with compressed files and directories is similar to working with uncompressed files and directories. Files that have been zipped in Linux can be recovered using a variety of tools on different platforms.

There are many methods to unzip files and directories. Some of them are described in detail in this article.

Unzip Files in Linux Terminal

Some of the methods to extract data from files are mentioned below

  • Unzip File using “unzip command”
  • Unzip File using “tar command”
  • Unzip File using “gunzip command”

Unzip File using unzip command

One of the most common methods to extract data from archived files using a terminal in Linux is by using unzip command. It’s preinstalled in new versions of Ubuntu and other Linux distributions but if you are using an older version you will need to install it by below-mentioned command.

$ sudo apt install unzip

The files zipped with “.zip” extension are unzipped by unzip command.

Syntax:

$ unzip filename.zip

Below mention command will unzip “linux1.zip” by unzip command:

$ unzip linux1.zip

Output:

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

Unzip File using tar command

Another most common method to extract data from archived files using a terminal in Linux is by using the tar command which comes pre-installed in Ubuntu, it stands for “tape archiver“ used to compress, and extract the compressed files and also 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

The below-mentioned command will unzip “linux2.tar” by tar command:

$ tar xvf linux2.tar

Output:

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

Unzip File using gunzip command

Another common way to extract data from archived files using a terminal in Linux is by using gunzip command, which also comes pre-installed. In Linux, the gunzip command compresses or expands a file or files and, replaces the archived file/files with the original file/files. After extraction, the file/files will regain their original extension. The files zipped with “.gz.z_z-gz-z .Z.taz,.tgz” extension are unzipped by gunzip command.

Syntax:

$ gunzip filename.gz

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

$ gunzip linux3.txt.gz

Output:

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

Conclusion

Every operating system offers the possibility to compress files or directories with different methods to save disk space and to transfer files easily. The compressed files must be extracted. In this article, three methods of extracting compressed files are discussed in detail: Extracting files using “unzip”, “tar” and “gunzip” commands. You can choose one of the methods that you find easiest.