Personal tools
You are here: Home Members jgsack's Home pages (html) Tarballs ExpressHowto (Bsave)
Document Actions

Tarballs ExpressHowto (Bsave)

by James G. Sack last modified 2006-04-06 00:34

version b

Tarballs: X.tar.gz or X.tgz

Files with names like this are compressed archives; that is, they are archives (created by the tar program) that have been compressed (by the gzip program). Both naming conventions are commonly found, and imply the same content.

This Express Howto gives command-line examples of viewing, creating, and extracting these so-called (mildly-geekish) tarballs.

2-minute background

Compressed means that data content has been encoded (translated) by the use of some lossless compression algorithm, for the purpose of reducing the size of the data. A lossless reduction is only possible if there is some redundancy in the data. As a simplified explanation, compression algorithms typically substitute short abbreviations for common patterns. The compression format typically stores the encoding formula (or map), along with the encoded data, so that a subsequent decoding step can recover the original data.

Archive means that multiple files, possibly a hierarchy of subdirectories plus files, are packed together in a single file for convenience of communicating, or transporting, or simply for saving current copies for future reference. The archiving format typically includes special information blocks (headers) that serve to delimit the files, and to store file properties (or metadata, such as timestamps and permissions).

The compressed archives tarball discussed here is quite common in the Unix/Linux community. Another slightly different strategy involves an archiving compressor, in which files are (individually) compressed and then the encoded files are combined to produce the end result. A common format for this strategy is X.zip. In some, (arguably most) situations, such zipfiles are actually a more convenient format, but the purpose of this discussion is to cope with tarballs.

Be aware that archiving and compressing could be done in separate steps, but many people use what might be called a single-command partnership operation, as shown in the examples that follow.

So, what does one do with a tarball?

Most importantly, you can create, extract, and inspect a tarball. The following sections give command-line examples for accomplishing those basic tasks. Perform these specific examples from within your home directory.

Creation: -c

tar -czvf themes.tgz -C /usr/share/gdm/ themes/

Notes: 
 -c is the create operation command-option
 -z is the gzip compression-filtering-option
 -v is the verbose option
 -f themes.tgz 
    is the tarball filename-specification-option
 -C /usr/share/gdm/
    tells tar to changedir to /usr/share/gdm/ to find the 
    targets (what things to store)
 themes/
    is the specification of things to store,
    namely a directory (-tree, tar is recursive by default)
Also:
 You could avoid the "C ..path.." part of the command, in 
   various ways, but is is good to get used to this format
   to avoid a variety of difficulties.
   Namely: tar -czvf usg_themes.tgz /usr/share/gdm/themes/
    would store themes-contents (with a long path prefix), AND
    give an warning message at the beginning of the operation:
     "tar: Removing leading '/' from member names"
    In general absolute names are undesirable, so GNUtar 
     automatically removes the leading slash -- but it can be 
     told not to (and other tars may behave differently)
    Further, extraneous path components are nicely removed by 
     the form using the -C.
 Finally, if you know about tab completion, you will note that
  the "-C /usr/share/gdm/ themes/" part of the command can be 
  constructed with a '/', tabs, backspace and spacebar, saving 
  great wear-and-tear on fingertips and keytops.

Inspection (list contents): -t

tar -tzvf themes.tgz

Notes: 
 -t is the list command-option
 -zvf themes.tgz
    mean the same thing as in the creation example
Also:
 note that the listed contents show relative paths starting 
 from the location given in the create command -C option

Extraction: -x

tar -xzvf themes.tgz

Notes: 
  -x is the extract command-option
  -zvf themes.tgz
     mean the same as before
Also:
- note that you have just created a new subdirectory tree in 
 your home directory. typing "tree themes/" on my system 
 reported a screenful of listings, followed by the summary 
 "4 directories, 41 files".  You may now remove that 400K or 
 so of themes, with the command "rm -rf themes/"
- the reason for not storing absolute paths in tarballs may
 now be easier to understand. With relative paths, you can 
 extract to wherever you specify. In some (most?) cases, it 
 would NOT be desirable to overwrite the originals by default.
- If you had really wanted to extract those files to the 
 original location, you would have had to be root (for write 
  permission), and you would have given the following command:
    tar -xzvf themes.tgz -C /usr/share/gdm/

things to remember

  • every tar command must have exactly one command-option

  • every tar operation on a compressed archive must have -z

    • if omitted you get a simple (uncompressed) tar archive (regardless of the name you gave it!)

  • every tar command operating on a tarball must have -f filespec

    • the -f option must directly precede the filespec (spaces ok, though)

  • all the example commands shown above may operate on multiple files (or dirs). For example, you may wish to try something like:

     tar -xzvf themes.tgz *screenshot* themes/circles/flower.png 
    

what about gui?

The standard desktop file browsers (eg, nautilus, konqueror) will actually allow operating on tarballs with a gui interface. In the gnome (nautilus) case, an auxiliary program file-roller is invoked from the file browser.

These gui interfaces are actually quite convenient for allowing you to view the contents of tarballs (and zipfiles, etc). Especially nice, is the ability of file-roller to either view all files or view a folder-at-a-time. konqueror can show a nice treeview, that some may prefer.

Although these gui interfaces offer options to create new tarballs, to extract all-or-part of a tarball, and even to add files and folders to existing tarballs, it is recommended that you use the gui tools only for viewing listings archives, at least until gaining some experience with command line creation and extraction operations.

more info

  • man tar

  • info tar


Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: