20.8 C
Texas
Melhttp://www.osradar.com
Guru Unix /Linux and GNU supporter

How to Compress and Decompress Files on Linux

Linux is really powerful platform loaded with strong compressing and decompressing mechanisms built-in. For Linux users, you may already have learned the name of .ZIP, .GZ, .TAR.GZ, .TGZ, .BZ2 etc. file types, right? These are different file compression methods and file types that Linux support by default. You can compress and decompress files into the formats on all the Linux distros.

Now, let’s take a look how to compress files into the following format.

Compressing files

  • ZIP

Zip is definitely one of the most popular compressed file formats. It’s widely used in all the platforms and really powerful for basic usage.

- Advertisement -

For compressing, ZIP uses the following structure:

zip {.zip-filename} {filename-to-compress}

If you want to compress a directory using ZIP, run this command:

zip -r {.zip-filename} {directory-to-compress}

In this example, I’m going to compress my Thunderbird profile. It’s also an awesome trick for backing up your Thunderbird profile.

zip -r thunderbird-backup.zip ~/.thunderbird

For decompressing the ZIP file, run this command:

unzip thunderbird-backup.zip
  • TAR

It’s a really powerful tool for compressing and decompressing the file(s) and directory. It’s more widely used as it offers more support for advanced compressing formats like TAR.BZ2. For compressing a file or directory using TAR command, follow the following structure:

tar -zcvf {.tgz-file} {files/directory} [using gzip compression method]
tar -jcvf {.tbz2-file} {files/directory} [using bz2 compression method]

For example, I’ll be compressing my “~/.thunderbird” directory. If you want to compress the file(s), just exchange the later part of the command.

tar -jcvf thunderbird-email-profile.tar.bz2 .thunderbird

For decompressing the file, run this command:

tar -xvf thunderbird-email-profile.tar.bz2

There’s also another file type called XZ. This one follows extreme compression method and used for compressing lots of small files into one, tight archive.

For turning into XZ archive, use the following command structure:

tar -cvJf filename.tar.xz /directory/*
  • GZIP & BZIP2

These tools also come pre-installed in most of the Linux distros. They’re not used as frequently as they lack the ability to compress directory. These are generally there for serving as the algorithm source for other software like TAR. However, you can still use them in the same way. The command line structure is quite same.

gzip {filename}
bzip2 {filename}

For decompressing a compressed file, use the following commands:

bzip2 -d {.bz2-file}
gzip -d {.gz file}

Voila! Enjoy the powerful compression feature of Linux!

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

LEAVE A REPLY

Please enter your comment!
Please enter your name here



Latest article