Monday, April 11, 2011

Compression & Backup


gzip:
1.#seq 100000 > 1lakh.txt (creating a file with the content 100000)
2.#gzip -c 1lakh.txt > 1lakh.txt.gz (compressing the file)
3.#gzip -l 1lakh.txt.gz  (showing the compression rate)
4.#gunzip 1lakh.txt.gz (uncompress the file)
5.#zcat 1lakh.txt.gz (view the content without decompressing)
or
#zcat 1lakh.txt.gz | less

bzip2: (best compression)
6.#bzip2 -c 1lakh.txt > 1lakh.txt.bz2 (compressing using algorithm bzip2)
7.#bzcat 1lakh.txt.bz2  (view the content without decompressing)
or
#bzcat 1lakh.txt.bz2 |less
8.#bunzip2 1lakh.txt.bz2  (decompressing using bzip2)

Zip:
9.#zip 1lakh.txt.zip 1lakh.txt (compressing using zip)
10.#unzip 1lakh.txt.zip (uncompress the file)

Tar & Gzip, Bzip2 (Tape Drive Archieve or backup):
create a directory special and put some contents in that.
11.#tar -cvf myfile.tar special/ (taking backup)
12.#tar -cvf myfile.tar 1lakh.txt.gz (adding another file in the same tar)
13.#tar -czvf myfile.tar.gz special/ (creating tar & gzip together)
14.#tar -cjvf myfile.tar.bz2 special/ (creating tar & bzip2 together)
15.#tar -tzvf myfile.tar.gz (viewing the gzip without extraction)
16.#tar -cjvf myfile.tar.bz2 special.save/ (viewing the files)
17.#tar -xvf myfile.tar.gz (extracting gzip file)
18.#tar -xvf myfile.tar.bz2 (extracting bzip2 file)

0 Comments: