Linux Format

A quick reference to… tar

-

You won’t spend long using Linux before you come across a TAR file. These files, usually referred to as tarballs, are archives of one of more files. They fulfil a similar function to the ZIP files commonly used on Windows. The TAR format was originally designed for tape drives (the name is a contractio­n of Tape Arrchive), so TAR archives themselves are not compressed, as tape drives generally have built-in compressio­n.

However, it is normal to see tarballs with a TAR.GZ, TAR.BZ2 or TAR.XZ extension, meaning they have been compressed with Gzip, Bzip2 or xz. It is not necessary to worry about the type of compressio­n applied to a tarball; tar will recognise it (even if the file is named incorrectl­y) and handle it internally. To unpack a tarball to the current directory, use

$ tar xf tarfile.tar.xz

To unpack to a different directory, add -C some/directory . If you want to list the contents of a tarball rather than extracting them, replace the x (for extract) in the first command with t , for test – so-named because this command also tests the integrity of the tarball. Creating tarballs is as simple as replacing the x with c (for create) and listing the files or directorie­s to include, such as

$ tar cf documents.tar Documents

This will archive your Documents

folder, but without compressio­n – which is pretty inefficien­t, especially if you want to store this file online or email it to someone. To compress it with xz, the best combinatio­n of speed and compressio­n these days, use:

$ tar cjf documents.tar.xz Documents

The full list of arguments are listed in the tar man page, or you could cheat and do it all from your file manager.

Newspapers in English

Newspapers from Australia