Command Line Tips: Compress & Extract Files

Learn how to compress and extract files with the most important and used tools: TAR, TAR with GZIP, GZIP, BZIP2, ZIP and RAR.

GitHub.com - begin2dev/technical-disclosure

Command Line Tips

Compress & Extract Files

Let's see the most used tools to compress and extract files: TAR, TAR with GZIP, GZIP, BZIP2, ZIP and RAR.


There are different ways to compress and extract files, and it depends on the compression algorithm used to reduce the files size. The most used and important compression methods are:

It is useful to know how to use them in order to work with this kind of files.

Most of them are used by writing the right command line.

When you download a software package, it will usually be compressed, so the first thing you have to do is to extract all the files.

Which one is your favorite? Which one do you think is widely used?

TAR (.tar)

Compress files with TAR

tar cvf archive.tar /path/to/files/directory/*

Extract TAR file

tar xvf archive.tar

TAR with GZIP (.tar.gz or .tgz)

Compress files with TAR and GZIP

tar czvf archive.tgz /path/to/files/directory/*

Extract TAR and GZIP file

tar xzvf archive.tgz

GZIP (.gz)

Compress files with GZIP

gzip -q archive.gz /path/to/files/directory/*

Extract GZIP file

gzip -d archive.gz

BZIP2 (.bz2)

Compress files with BZIP2

bzip2 -z /path/to/files/directory/*

Extract BZIP2 file

bzip2 -d archive.bz2

ZIP (.zip)

Compress files with ZIP

zip archive.zip /path/to/files/directory/*

Extract ZIP files

unzip archive.zip

RAR (.rar)

Compress files with RAR

rar a archive.rar /path/to/files/directory/*

Extract RAR file

rar x archive.rar


Please visit Instagram | @begin2dev | Compress & Extract Files post.
Likes and comments are always welcome!
Let me know if you like this kind of contents.