Who's Online

We have 4 guests online
How to compress zip,rar and bzipped files in linux? PDF Print E-mail
Written by Deepak K.C.   
Friday, 08 May 2009 16:35

File Compression:

File Compression is simply to store a group of files in a single file. We do it usually when we have to create backups or to transfer from one directory to another. The compressed files occupy less space and hence its download faster via the internet. File archiving is a collection of files and directories which are stored in a file . The archive file is not compressed (it uses the same amount of disk space ,no difference in real file size and the archived ones) .

We use compression tools like gzip,bzip2, zip etc. to compress files or directories.



When to compress files?

1.No enough hard disk space
2.Need to share files either via internet or from one directory to another

Extracting

Extracting is simply to decompress the compressed files or directories by using certain tools like gunzip,bunzip2, unzip etc.

Unzip


To  unzip rar files we need to install unrar command

deep@deep-laptop:~deep@deep-laptop:~$ sudo apt-get install unrar


Installing Unrar (other way incase the above doesn't work)

deep@deep-laptop:~$ cd /tmp

deep@deep-laptop:~$ wget http://www.rarlab.com/rar/rarlinux-3.6.0.tar.gz
 
Untar file

deep@deep-laptop:~$ tar -zxvf rarlinux-3.6.0.tar.gz
deep@deep-laptop:~$ cd rar
deep@deep-laptop:~$ ./unrar


Now copy rar and unrar to /bin directory:
deep@deep-laptop:~$ cp rar unrar /bin

Using Unrar to unpack rar files

deep@deep-laptop:~$ unrar e file.rar

Bzip2 and Bunzip2


To compress file using bzip2


 deep@deep-laptop:~$ bzip2 filename

The above command will compress the file named filename and save as filename.bz2

To expand the bz2 compressed file

deep@deep-laptop:~$bunzip2 filename.bz2

The filename.bz2 is deleted and replaced with filename.

Using bzip2 to compress multiple files



 deep@deep-laptop:~$bzip2 filename.bz2 file1 file2 file3 /home/deep/Desktop


This will compress the files named file1,file2,file3 and the contents of the directory desktop to the single file named filename.bz2.

Note: the files to be compressed are simply separated by single space.

Gzip and Gunzip

Using  gzip to compress a file:

 deep@deep-laptop:~$gzip filename

The file named filename.gz is a compressed file.

Expanding gz compressed file


 deep@deep-laptop:~$gunzip filename.gz

The filename.gz is deleted and replaced with filename.



Using gzip to compress multiple files and directories :

 deep@deep-laptop:~$gzip -r filename.gz file1 file2 file3  /home/deep/Desktop/

This will compress files named file1,file2,file3 and the contents of the desktop directory.

Zip and Unzip

Compressing file with Zip

 deep@deep-laptop:~$zip -r file.zip /home/deep/Desktop

The above command will create a zipped file named file.zip and the contents of desktop directory. The -r option specifies to include all files from the directory recursively.

Extracting  the contents of a zip file


 deep@deep-laptop:~$unzip file.zip

Compressing multiple and files and directories :

 deep@deep-laptop:~$zip -r filename.zip file1 file2 file3 /home/deep/Desktop

The above command compresses file1, file2, file3, and the contents of the /home/deep/Desktop directory into a file named filename.zip


Comments
Add New Search
Write comment
Name:
Email:
 
Title:
UBBCode:
[b] [i] [u] [url] [quote] [code] [img] 
 
:angry::0:confused::cheer:B):evil::silly::dry::lol::kiss::D:pinch:
:(:shock::X:side::):P:unsure::woohoo::huh::whistle:;):s
:!::?::idea::arrow:
Please input the anti-spam code that you can read in the image.

!joomlacomment 4.0 Copyright (C) 2009 Compojoom.com . All rights reserved."

Last Updated on Sunday, 31 May 2009 02:39