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 newsletter!

Error: Please check your email address.
Rocket to Success - Your 10 Tips for Smarter ERP System Selection
Keep up with the latest tech news, reviews and previews by subscribing to the Good Gear Guide newsletter.

Alastair Cousins

PC World
Show Comments

Cool Tech

Breitling Superocean Heritage Chronographe 44

Learn more >

SanDisk MicroSDXC™ for Nintendo® Switch™

Learn more >

Toys for Boys

Family Friendly

Panasonic 4K UHD Blu-Ray Player and Full HD Recorder with Netflix - UBT1GL-K

Learn more >

Stocking Stuffer

Razer DeathAdder Expert Ergonomic Gaming Mouse

Learn more >

Christmas Gift Guide

Click for more ›

Most Popular Reviews

Latest Articles

Resources

PCW Evaluation Team

Walid Mikhael

Brother QL-820NWB Professional Label Printer

It’s easy to set up, it’s compact and quiet when printing and to top if off, the print quality is excellent. This is hands down the best printer I’ve used for printing labels.

Ben Ramsden

Sharp PN-40TC1 Huddle Board

Brainstorming, innovation, problem solving, and negotiation have all become much more productive and valuable if people can easily collaborate in real time with minimal friction.

Sarah Ieroianni

Brother QL-820NWB Professional Label Printer

The print quality also does not disappoint, it’s clear, bold, doesn’t smudge and the text is perfectly sized.

Ratchada Dunn

Sharp PN-40TC1 Huddle Board

The Huddle Board’s built in program; Sharp Touch Viewing software allows us to easily manipulate and edit our documents (jpegs and PDFs) all at the same time on the dashboard.

George Khoury

Sharp PN-40TC1 Huddle Board

The biggest perks for me would be that it comes with easy to use and comprehensive programs that make the collaboration process a whole lot more intuitive and organic

David Coyle

Brother PocketJet PJ-773 A4 Portable Thermal Printer

I rate the printer as a 5 out of 5 stars as it has been able to fit seamlessly into my busy and mobile lifestyle.

Featured Content

Product Launch Showcase

Latest Jobs

Don’t have an account? Sign up here

Don't have an account? Sign up now

Forgot password?