Linux offers a variety of ways to extract files from archives, including zip archives. Compression is truly a lifesaver when you have to send multiple files over, but you want it to be a single one. It can also save you up to 50% of storage. In this article, I will explain different ways how you can extract archives on Linux systems.
How to extract zip archives
To extract zip
archives, you can use the unzip
utility. In case it is not shipped by default, you can install it using your package manager of choice, e.g. apt-get install unzip
. Once it is available, you can use it like this:
> unzip filename.zip
You can also specify the destination folder like this:
> unzip filename.zip -d /extract/to/here
How to extract tar and tar.gz archives
These archives are a popular way to ship source code. To extract it, use the tar
command, which is included by default with all Linux systems. It has quite a confusing interface, but you really just need to know 2 commands. To extract a .tar
archive:
> tar xvf filename.tar
And for .tar.gz
you can use:
> tar zxvf filename.tar.gz
How to extract xz and tar.xz archives
tar.xz
is simular to tar.gz
, but it is using the LZMA algorithm, the same one 7z
is using. To work with .xz
archives, you need to install the xz-utils
package:
> apt-get install xz-utils
Now, to extract a .xz
archive, run:
> unxz filename.xz
To extract a tar.xz
file, use:
> tar xvf filename.tar.xz
How to extract 7z archives
7z
is another open-source compression algorithm, offering higher compression ratio than zip
. It is not shipped by default with Linux distributions, so you will have to install it manually:
> apt-get install p7zip-full
After it is installed, you can use it like this:
> 7z e filename.7z
How to extract rar archives
Unlike other compression methods, rar
is proprietary and cannot be shipped by default. Firstly, you need to install the unrar
utility:
> apt-get install unrar
To extract a .rar
archive, use:
> unrar x filename.rar
You can also specify the folder to extract the content to:
> unrar x filename.rar ./extract/here
Closing notes
Thank you for reading, I hope now you will have no problem extracting archives on Linux systems.
Resources
man tar
man unzip
man unrar
man 7z
- 15 Essential Tips & Tricks for Linux Command Line
- 3 Ways to Find Files on Linux Systems