Tarballs ExpressHowto (A)
This has been superceded by 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 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 tarball-format compressed archives 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 usr_share_gdm_themes.tgz /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 usr_share_gdm_themes.tgz
is the tarball filename-specification-option
/usr/share/gdm/themes/
is the specification of things to store (namely a directory-tree)
Also:
there will be one warning message at the beginning of the operation:
"tar: Removing leading '/' from member names"
this is expected because an absolute path was given to the things-to-store
tar always converts absolute paths to relative paths, about which
more will be said below
Inspection (list contents): -t
tar -tzvf usr_share_gdm_themes.tgz
Notes:
-t is the list command-option
-zvf usr_share_gdm_themes.tgz
mean the same thing as in the creation example
Also:
note that the listed contents show no leading slash (paths are relative)
Extraction: -x
tar -xzvf usr_share_gdm_themes.tgz
Notes:
-x is the extract command-option
-zvf usr_share_gdm_themes.tgz
mean the same as before
Also:
- note that you have just created a new subdirectory tree in your home directory. typing "tree usr/" on my system reported a screenful of listings, followed by the summary line "7 directories, 41 files". You may now remove that 400K or so of themes, with the command "rm -rf usr"
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 -C / -xzvf usr_share_gdm_themes.tgz
or, equivalently
cd /
tar -xzvf /home/jsack/usr_share_gdm_themes.tgz
Special note:
-C / is an option that tells tar to changedir to / for the extraction
which is a useful thing to remember. It works on creation also, so
you may wish to try:
tar -C /usr/share/gdm -czvf themes.tgz themes
and note that there will be no warning this time, and that the relative path
will start with themes this time.
things to remember
every tar command must have exactly one command-option
every tar operation on a compressed archive must have -z
every tar command operating on a tarball must have -f filespec
the -f option must dierectly precede the filespec (space ok)
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 operations of creation and extraction.
more info
man tar
info tar
TarballExpress (last edited 2006-04-04 22:17:35 by JamesGSack)