Categories
Info

Handling archives in linux

How to compress/decompress files in Linux.
Zip files
To compress of decompress zip files you must have the following programs installed in your computer

zip to compress files
unzip to decompress files

here are the commands
to zip a single file

$zip archive_name.zip file_name

to zip a single folder use the folder name instead of file_name

$zip -r archive_name.zip folder_name

to zip multiple files use

$zip archive_name.zip file1 file2 file3 file4 file5

you can also zip a combination of files and folders into one zip file like this

$zip -r archive_name.zip file1 file3 file4 folder_name1/ folder2/ folder3/

to unzip a file u need unzip program installed in your system

$unzip file.zip

to view data in the zip file use

$unzip -v file.zip

Rar files
You need the rar program from rarlabs.com to compress/decompress these files or you can use unrar or unrar-nonfree packages

$rar -a file.rar /folder/

to uncompress use

$rar -x file.rar

to view the data in the file use

$rar -v file.rar

Tar Files
to compress files into a tar archive use

$tar cvf file.tar folder/ *

to unpack or to uncompress us

$tar -xvf file.tar

to view data in the tar file use

$tar -tvf file

Here the ‘v’ is optional, it just gives verbose output

Tar.gz files
to compress into .tar.gz use

$tar czvf file.tar.gz folder

to uncompress use

$tar xzvf file.tar.gz

to view data in the tar.gz file use

tar tzvf file.tar.gz

bz2 files
to compress into bz2 format use bzip2

$bzip2 file

above command will create an archive named file.bz2. Also bz2 works on only files.
So if you want to compress a folder you have to pack it into a tar file first and use bzip2 on it.
to uncompress or unpack use

$bzip2 -d file.bz2

tar.bz2 files
to compress into a tar.bz2 file use

$tar cjvf file.tar.bz2 folder

to uncompress tar.bz2 files use

$tar -xjvf file.tar.bz2

to view data in the file use

$tar -tjvf file.tar.bz2