There are various compression formats of which the mostly used under GNU/Linux are gzip and bzip2.

Compression

tar.gz

To use gzip to create .gz package, we need to first create a container. For that tar can be used. Packaging files into a container and compression are two different things. gzip is mainly used for compression of a single file, which can be a container made from tar as well.

tar -cvf filename.tar dir-or-file
gzip filename.tar

tgz

It is same as tar.gz done using tar.

tar -czvf filename.tgz file-or-dir

tar.bz2

tar -cvf filename.tar file-or-folder
bzip2 filename.tar
# OR
tar -cvjf filename.tar.bz2 file-or-folder

Both gzip and bzip2 will delete the source file after compression.

Decompression (expand)

tar.gz or tgz

tar -zxvf filename.tar.gz  # or filename.tgz

tar.bz2

tar -xvjf filename.tar.bz2