How to Extract Files in Linux

Much of the content we find on the Internet is compressed and once downloaded you have to extract it. If you are going to send attachments by email, it is more efficient to send it packaged and compressed, and the simple fact of making backup copies of developments or personal folders is quite simplified.

This guide we’ll be focusing on how you can extract files in Linux.

How to Extract Files in Linux

Currently there are a lot of compression algorithms such as .zip, .tar, .tar.gz, 7z, etc.

zip

zip is one of the most common compression algorithms to combine or group multiple files or directories into one. To extract .zip files in Linux we need install unzip.

Debian/Ubuntu (or Debian-based distros)

We’ll be using the apt command to install unzip.

sudo apt-get install -y unzip

RHEL/CentOS/Fedora

Similar to debian/ubuntu we’ll use the yum command to install zip

sudo yum install unzip

Now that we have unzip installed, simply we need unzip the file:

sudo unzip file_name.zip
Example output

[root@localhost-live Downloads]# sudo unzip file.zip 
Archive:  file.zip
  inflating: index.jpg               
  inflating: image.jpg               
[root@localhost-live Downloads]# 

Do note that you can have multiple flags when using the unzip command, to view them please visit the die.net page of unzip.

tar / tar.gz

Similar to zip, tar combines or groups multiple files and/or directories into a single .tar file.

Fun fact: Its name (tar) is short for tape archive, as this was created to store such files in magnetic tape.

By default tar is already install in all modern Linux distros by default, but in case you don’t already have it installed:

sudo apt-get install tar #Debian-based distros (Ubuntu, Mint, etc.)

yum install tar #RHEL-based distros (CentOS, Fedora, etc.)

To extract any .tar and .tar.gz we can use the following syntax:

tar flags file_name.tar

The most common flags used are:

  • -x – Extract files from the archive. (Must use for extracting any .tar/.tar.gz)
  • -v – Verbose mode. It outputs what its doing.
tar -xv files.tar

tar -xv file.tar.gz

7z

.7z is simple file archiver with higher compression ratios than .zip and .tar/.tar.gz.

To extract a .7z file we need to install p7zip

sudo apt-get install p7zip-full #Debian-based distros (Ubuntu, Mint, etc.)

yum install p7zip #RHEL-based distros (CentOS, Fedora, etc.)

Once we have p7zip installed we can extract .7z files with the help of the 7z command along with the x flag to extract:

7z x file_name.7z
Example output

┌─[linuxify@linuxify]─[~/Desktop]
└──╼ $7z x file.7z 

7-Zip [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=en_CA.UTF-8,Utf16=on,HugeFiles=on,64 bits,2 CPUs AMD Ryzen 7 3700X 8-Core Processor              (870F10),ASM,AES-NI)

Scanning the drive for archives:
1 file, 54054 bytes (53 KiB)

Extracting archive: file.7z
--
Path = file.7z
Type = 7z
Physical Size = 54054
Headers Size = 276
Method = LZMA2:16
Solid = +
Blocks = 1

Everything is Ok

Files: 3
Size:       54290
Compressed: 54054

Summary

In this short guide we learned how we can easily extract files in linux. More specifically how we can extract .zip, .tar, .tar.gz and .7z files.

Leave a Comment