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.

Our Back to Business guide highlights the best products for you to boost your productivity at home, on the road, at the office, or in the classroom.

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

Alastair Cousins

PC World
Show Comments

Essentials

Microsoft L5V-00027 Sculpt Ergonomic Keyboard Desktop

Learn more >

Lexar® JumpDrive® S57 USB 3.0 flash drive

Learn more >

Mobile

Lexar® JumpDrive® S45 USB 3.0 flash drive 

Learn more >

Exec

Audio-Technica ATH-ANC70 Noise Cancelling Headphones

Learn more >

Lexar® Professional 1800x microSDHC™/microSDXC™ UHS-II cards 

Learn more >

Lexar® JumpDrive® C20c USB Type-C flash drive 

Learn more >

HD Pan/Tilt Wi-Fi Camera with Night Vision NC450

Learn more >

Budget

Back To Business Guide

Click for more ›

Most Popular Reviews

Latest News Articles

Resources

PCW Evaluation Team

Azadeh Williams

HP OfficeJet Pro 8730

A smarter way to print for busy small business owners, combining speedy printing with scanning and copying, making it easier to produce high quality documents and images at a touch of a button.

Andrew Grant

HP OfficeJet Pro 8730

I've had a multifunction printer in the office going on 10 years now. It was a neat bit of kit back in the day -- print, copy, scan, fax -- when printing over WiFi felt a bit like magic. It’s seen better days though and an upgrade’s well overdue. This HP OfficeJet Pro 8730 looks like it ticks all the same boxes: print, copy, scan, and fax. (Really? Does anyone fax anything any more? I guess it's good to know the facility’s there, just in case.) Printing over WiFi is more-or- less standard these days.

Ed Dawson

HP OfficeJet Pro 8730

As a freelance writer who is always on the go, I like my technology to be both efficient and effective so I can do my job well. The HP OfficeJet Pro 8730 Inkjet Printer ticks all the boxes in terms of form factor, performance and user interface.

Michael Hargreaves

Windows 10 for Business / Dell XPS 13

I’d happily recommend this touchscreen laptop and Windows 10 as a great way to get serious work done at a desk or on the road.

Aysha Strobbe

Windows 10 / HP Spectre x360

Ultimately, I think the Windows 10 environment is excellent for me as it caters for so many different uses. The inclusion of the Xbox app is also great for when you need some downtime too!

Mark Escubio

Windows 10 / Lenovo Yoga 910

For me, the Xbox Play Anywhere is a great new feature as it allows you to play your current Xbox games with higher resolutions and better graphics without forking out extra cash for another copy. Although available titles are still scarce, but I’m sure it will grow in time.

Featured Content

Latest Jobs

Don’t have an account? Sign up here

Don't have an account? Sign up now

Forgot password?