Ubuntu Pocket Guide and Reference

Page 112

To unzip files, the unzip command is used. The following will extract the files from archive.zip: unzip archive.zip

To list files in an archive prior to unzipping, use the -l command option: unzip -l archive.zip

You can subsequently unzip a single file from the archive by specifying its filename (and path, if it’s contained within a subfolder within the zip!) after specifying the archive name. The following will extract only report.doc from archive.zip: unzip archive.zip report.doc

tar archives

The tar command is both powerful and multi-faceted. It was originally designed for backup purposes, but works equally well for individual file/folder archiving. The elementary creation and extraction of tar archives is described in this section. The curious reader is advised to search online for more complete guides, of which there are a great many.

Creating a tar archive

The following will create a simple tar archive called archive.tar, containing the contents of the reports folder:

NOTE Remember that tar archives are not automatically compressed. They are simply container files. A tar file’s size reflects almost exactly the combined size of the files it contains:

tar cf archive.tar reports

The -c command option tells tar to create an archive, and the -f command option tells the tar command that the filename immediately follows. The -f option should always be added at the end of the range of command-options, immediately before the archive’s filename.

NOTE You might be wondering why the hyphen isn’t used before command options with the tar command. The answer is that it’s optional and so most people leave it out. A minority of commands make the hyphen optional, but most require it.

To additionally compress the archive, the -j or -z options can be added in for bzip2 or gzip compression, respectively. Bzip2 compression is considered most efficient and is arguably most common. Note that the

92 : Hands-on at the Command-Line


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.