Linux/Unix – Compressing Files

Compressed Files

File compression is useful for storing or transferring large files. When you compress a file, you shrink it and save disk space. File compression uses an algorithm to change the data in the file; to use the data in compressed files; you must first uncompress it to restore the original data (and original file size). The following recipes explain how to compress and uncompress files.

 

Compressing a File

Use the gzip (“GNU zip”) tool to compress files. It takes as an argument the name of the file or files to be compressed; it writes a compressed version of the specified files, appends a `.gz’ extension to their file names, and then deletes the original files.  To compress the file `war−and−peace’, type: $ gzip war−and−peace

This command compresses the file `war−and−peace’, putting it in a new file named `war−and−peace.gz’; gzip then deletes the original file, `war−and−peace’.

 

Decompressing a File

To access the contents of a compressed file, use gunzip to decompress (or “uncompress”) it.

Like gzip, gunzip takes as an argument the name of the file or files to work on. It expands the specified files, writing the output to new files without the `.gz’ extensions, and then deletes the compressed files. To expand the file `war−and−peace.gz’, type: $ gunzip war−and−peace.gz

This command expands the file `war−and−peace.gz’ and puts it in a new file called `war−and−peace’; gunzip then deletes the compressed file, `war−and−peace.gz’.

 

NOTE: You can view a compressed text file without uncompressing it by using zless. This is useful when you want to view a compressed file but do not want to write changes to it.

Advertisements

About msotela

This blog is for anyone who wants to access the power of a Linux system as a systems administrator or user. You may be a Linux enthusiast, a Linux professional, or possibly a computer professional who is increasingly finding the Windows systems in your data center supplanted by Linux boxes.

Posted on March 15, 2009, in Unix/Linux. Bookmark the permalink. Leave a comment.

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: