How to compress/extract file(s) and folder

While it exist a lot’s of compression program available (some are: arc,arj,bzip2,compress,dact,gzip,lzma,lzop,mscompress,p7Zip,PAQ8HP8,PPMd,rar,rzip,xz,zip,zoo), this post will show the simple way to compress and extract file(s) and folder using natif compression program provide with most distro.

File(s) Compression/Extraction

using bunzip2

compression:
bzip2 myfile.ext
compression without deletion:
bzip2 -c myfile.ext > myfile.ext.bz2
extraction:
bunzip2 myfile.ext.bz2

using gunzip
compression:
gzip myfile.ext
compression without deletion:
gzip -c myfile.ext > myfile.ext.gz
extraction:
gzip -d myfile.ext.gz

Folder Compression/Extraction

compression using bunzip2:
tar -jcvf myfolder.tar.bz2 myfolder
compression using gzip2:
tar -zcvf myfolder.tar.gz myfolder

extraction using bunzip2:
tar -jxvf myfolder.tar.bz2
extraction using gzip2:
tar -zxvf myfolder.tar.gz

note: during extraction, and on this particular example it will create the folder “myfolder” within the current location.

remark on the extension name:
.tar.bz2 can be replaced by .tbz or .tbz2
.tar.gz can be replaced by .tgz

For more detail on the program options don’t forget the man pages

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: