File Compression
An archive file is a collection of files and directories stored in one file. The archive file is not compressed — it uses the same amount of disk space as all the individual files and directories combined.
A compressed file is a collection of files and directories that are stored in one file and stored in a way that uses less disk space than all the individual files and directories combined.
An archive file is not compressed, but a compressed file can be an archive file.
Compressing Files at the Shell Prompt
Redhat Linux has utilities like gzip, and zip tools for compression from a shell prompt. Use zip because it is more compatible with the compression utilities available for Windows.
Compression Tool File Extension Decompression Tool
gzip .gz gunzip
zip .zip unzip
Compression Tools
By convention, f files compressed with gzip are given the extension .gz, and files compressed with zip are given the extension .zip
. files compressed with gzip are uncompressed with gunzip, and files compressed with zip are uncompressed with unzip.
Gzip and Gunzip
To use gzip to compress a file, enter the following command at a shell prompt:
eg:gzip filename
The file is compressed and saved as filename.gz.
To expand the compressed file, enter the following command:
eg: gunzip filename.gz
The filename.gz compressed file is deleted and replaced with filename.
In linux you can use gzip to compress multiple files and directories at the same time by listing them with a space between each one:
gzip -r filename.gz file1 file2 file3
The above command compresses file1, file2, file3.
Zip and Unzip
To compress a file with zip, enter the following command:
eg: zip -r filename.zip filesdir
In the above example, filename.zip represents the file you are creating and filesdir represents the directory you want to put in the new zip file. The -r option specifies that you want to include all files contained in the files directory recursively.
To extract the contents of a zip file, enter the following command:
eg: unzip filename.zip