Last Updated: February 25, 2016
·
2.254K
· pmaoui

Compress and Uncompress anything on Linux

This is a serie of lessons of “Basic Commands “ that focuses on command-line usage.


Tarball (tar):

Create a uncompressed tarball :

tar -cvf archive.tar file1

Create an archive containing ‘file1′, ‘file2′ and ‘dir1:

tar -cvf archive.tar file1 file2 dir1 

Show contents of an archive:

tar -tf archive.tar

Extract a tarball :

tar -xvf archive.tar

Extract a tarball into / tmp :

tar -xvf archive.tar -C /tmp

Create a tarball compressed into bzip2

tar -cvfj archive.tar.bz2 dir1

Decompress a compressed tar archive in bzip2

tar -xvfj archive.tar.bz2

Decompress a compressed tar archive in gzip

tar -cvfz archive.tar.gz dir1

Decompress a compressed tar archive in gzip

tar -xvfz archive.tar.gz 

Meanning of the c,v,f and z,j options:
-’c’ option tells tar to create an archive,
-’v’ displays the files added to the tarball and
-’f’ specifies the filename. After the filename, all other parameters are the files or directories to add to the archive.
Tarballs are commonly compressed using gzip or bzip2 using the -z or -j command options.


bzip2 :

Compress a file called ‘file1′

bzip2 file1

Compress a file called ‘file1′

bzip2 file1

Decompress a file called ‘file1.bz2′

bunzip2 file1.bz2 

RAR Archiver :

Create an archive rar called ‘file1.rar’

rar a file1.rar test_file

Compress ‘file1′, ‘file2′ and ‘dir1′ simultaneously

rar a file1.rar file1 file2 dir1

Decompress rar archive

rar x file1.rar

OR
unrar x file1.rar


Gzip :

Decompress a file called ‘file1.gz’

gunzip file1.gz

Compress a file called ‘file1′

gzip file1

Compress with maximum compression

gzip -9 file1

ZIP Archiver:

Create an archive compressed in zip

zip file1.zip file1

Compress in zip several files and directories simultaneously

zip -r file1.zip file1 file2 dir1

Decompress a file called file1

unzip file1 

See more at: http://www.unixmen.com/basic-commands-les-i-compress-and-decompress-files-using-rar-bzip-tarballtar-and-gunzip/#sthash.KrfUvBFL.dpuf

1 Response
Add your response

Nice list that can come in handy. You can also use atool for managing file archives of various types with a single command (see atool's man page for usage information).

over 1 year ago ·