Wednesday, February 24, 2010

Debian 6

Tar, Gzip, Bzip2 and Zip allows compression and ability to roll files and directories into one file. Gzip handles the compression and decompression of Gzip (*.gz) files.
To compress a file, use the following syntax:
gzip -c test.txt > test.gz

By default, if we use -c, it will generate large amounts of output to the screen (STDOUT). You will need to use output redirection as shown to output to a file. If you accidentally miss out the output redirection, you will likely have your prompt corrupted. To fix all corrupted prompts, type:

Gzip has a built-in function to reveal compression statistics. To do this, use the -l parameter:
gzip -l test.gz

Right now we have a test.gz file. We want to unzip this file, so we use the Gunzip utility:
gunzip test.gz

When you gunzip something, it removes the compressed file by default.

Another utility that decompresses gzip files is zcat which prints to STDOUT:
zcat test.gz

You can also pass the -d parameter into gzip, which is similar to gunzip.

Bzip2 is used to handle Bzip2 (*.bz2) files. Bzip2 works better than Gzip for larger files. Usage of Bzip2 is very similar to Gzip (same paramters, etc). Bzip2, however, cannot show statistics about a file.

You can use the "file" command to show a file's type:
file test.txt.bz2

The zcat equivalent in Bzip2 is bzcat. The gunzip equivalent is bunzip.

Less has a built-in decompressor so it can read compressed files in plain text.

When you see .tar.gz, it means that it's a tape archive compressed with gzip.

One of the oldest compression programs for Linux is the zip and unzip. The syntax for zip is:
zip target source

For unzip, it's:
unzip source

unzip supports the -l option to show statistics. zcat works on zip files as well.

Tar (which stands for Tape Archive) allows to role one or more files and/or directories into one file. Tar can be compressed or uncompressed. To create a Tar file, use:
tar -cvf output input [input2] [input3] ...

To display the contents of the tar archive:
tar -tvf file.tar

Tar can use the Gzip algorithm through:
tar -czvf output input [input2] [input3] ...

Typically the file has the extension .tar.gz. Swapping the z to a j will result in Bzip2 being used. To decompress, use:
tar -xjvf input output

No comments :

Post a Comment