Archiving and compression in Linux

Archiving and compressing files is a very common task. Whether it is for backup purposes or exchanging files over the Internet, being able to handle the various archive and compression formats available is an important skill. Linux has tools to access all common archive and compression file formats.

Windows formats


Zip is the most popular compression format on any platform. The Zip format was originally created by PKWare in the 1980s and is now supported by hundreds of programs and used primarily to distribute software over the Internet. Linux uses Info-Zip (www.info-zip.org) to access Zip files. Tools to archive, compress and decompress files are included.

To create a Zip archive containing several files, use the following command:

$ zip archive.zip [files to zip separated by spaces]

To decompress a zip archive, use the following command:

$ unzip archive.zip

RAR is a very popular format for distributing large files on the Internet because it supports multi-volume archiving. This allows a single large archive to be broken into several RAR files of an identical size, commonly referred to as ‘disks’. This makes it much easier to transfer the archive using a relatively slow Internet connection such as a modem.

RAR files are created in sequential order, commencing with the suffix .rar for the first file, followed by .r00, .r01, etc. for each subsequent archive.

To create a multi-volume RAR archive, use the following command:

$ rar a -v archive.rar [files to RAR separated by spaces]

The ‘a’ command tells RAR to create an archive. The ‘-v’ switch splits the archive into disks of KB.

To decompress an RAR archive, place all of the disks in the current directory and type:

$ rar x archive.rar

The ‘x’ command tells RAR to extract the archive with full paths intact. RAR will automatically decompress the disks in the correct order.

UNIX formats


Under UNIX, archiving and compressing tasks are given to different programs.

Tape ARchiver or tar, is the standard archiving tool for UNIX, and was originally designed to be used with tape backups. The tar program takes a list of files and combines them into a single file. No compression is applied so the file will take up approximately the same amount of space as the original files.

To create a tar archive, use the following command:

$ tar cvf archive.tar [files to tar separated by spaces]

The ‘c’ switch tells tar to create a new archive. The ‘v’ switch turns on verbose mode to make diagnosing errors easier. The ‘f’ switch specifies that the archive filename follows.

To extract a tar archive into the original list of files, use the following command:

$ tar xvf archive.tar

The ‘x’ switch tells tar to extract files from an archive. The other switches have the same functionality as above.

GZip is a popular compression tool, and files compressed this way end in the suffix .gz. It is most commonly applied to tar archives, resulting in files ending with the suffix .tar.gz.

To create a GZip compressed archive, first create a tar archive of the files you wish to compress and then use the following command:

$ gzip archive.tar

To extract a GZip compressed file, use the following command:

$ gunzip archive.tar.gz

You can also take advantage of UNIX pipes to use gunzip and tar together:

$ gunzip -c archive.tar.gz | tar xv

The ‘-c’ switch outputs the contents of the decompressed archive.tar.gz to the tar command, which then extracts the individual files from the archive.

BZip2 offers significantly better compression than GZip and requires a lot more CPU power. BZip2 is best used to compress large files where the space savings are worth the extra time taken to compress the file.

To create a BZip2 compressed archive, first create a tar archive of the files you wish to compress and then use the following command:

$ bzip2 archive.tar

To extract a BZip2 compressed archive, use the following command:

$ bunzip2 archive.tar.bz2

You can also use take advantage of UNIX pipes to use BZip2 and tar together:

$ bunzip2 -c archive.tar.bz2 | tar xv

Join the PC World newsletter!

Error: Please check your email address.

Struggling for Christmas presents this year? Check out our Christmas Gift Guide for some top tech suggestions and more.

Keep up with the latest tech news, reviews and previews by subscribing to the Good Gear Guide newsletter.

Alastair Cousins

PC World

Most Popular Reviews

Follow Us

Best Deals on GoodGearGuide

Shopping.com

Latest News Articles

Resources

GGG Evaluation Team

Kathy Cassidy

STYLISTIC Q702

First impression on unpacking the Q702 test unit was the solid feel and clean, minimalist styling.

Anthony Grifoni

STYLISTIC Q572

For work use, Microsoft Word and Excel programs pre-installed on the device are adequate for preparing short documents.

Steph Mundell

LIFEBOOK UH574

The Fujitsu LifeBook UH574 allowed for great mobility without being obnoxiously heavy or clunky. Its twelve hours of battery life did not disappoint.

Andrew Mitsi

STYLISTIC Q702

The screen was particularly good. It is bright and visible from most angles, however heat is an issue, particularly around the Windows button on the front, and on the back where the battery housing is located.

Simon Harriott

STYLISTIC Q702

My first impression after unboxing the Q702 is that it is a nice looking unit. Styling is somewhat minimalist but very effective. The tablet part, once detached, has a nice weight, and no buttons or switches are located in awkward or intrusive positions.

Latest Jobs

Shopping.com

Don’t have an account? Sign up here

Don't have an account? Sign up now

Forgot password?