[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.7 How to List Archives

Frequently, you will find yourself wanting to determine exactly what a particular archive contains. You can use the `--list' (`-t') operation to get the member names as they currently appear in the archive, as well as various attributes of the files at the time they were archived. For example, you can examine the archive `collection.tar' that you created in the last section with the command,

$ tar --list --file=collection.tar

The output of tar would then be:


The archive `bfiles.tar' would list as follows:


Be sure to use a `--file=archive-name' (`-f archive-name') option just as with `--create' (`-c') to specify the name of the archive.

If you use the `--verbose' (`-v') option with `--list', then tar will print out a listing reminiscent of `ls -l', showing owner, file size, and so forth. This output is described in detail in verbose member listing.

If you had used `--verbose' (`-v') mode, the example above would look like:

$ tar --list --verbose --file=collection.tar folk
-rw-r--r-- myself/user      62 1990-05-23 10:55 folk

It is important to notice that the output of tar --list --verbose does not necessarily match that produced by tar --create --verbose while creating the archive. It is because GNU tar, unless told explicitly not to do so, removes some directory prefixes from file names before storing them in the archive (See section Absolute File Names, for more information). In other words, in verbose mode GNU tar shows file names when creating an archive and member names when listing it. Consider this example:

$ tar --create --verbose --file archive /etc/mail
tar: Removing leading '/' from member names
$ tar --test --file archive

This default behavior can sometimes be inconvenient. You can force GNU tar show member names when creating archive by supplying `--show-stored-names' option.


Print member (as opposed to file) names when creating the archive.

You can specify one or more individual member names as arguments when using `list'. In this case, tar will only list the names of members you identify. For example, tar --list --file=afiles.tar apple would only print `apple'.

Because tar preserves file names, these must be specified as they appear in the archive (i.e., relative to the directory from which the archive was created). Therefore, it is essential when specifying member names to tar that you give the exact member names. For example, tar --list --file=bfiles.tar birds would produce an error message something like `tar: birds: Not found in archive', because there is no member named `birds', only one named `./birds'. While the names `birds' and `./birds' name the same file, member names by default are compared verbatim.

However, tar --list --file=bfiles.tar baboon would respond with `baboon', because this exact member name is in the archive file `bfiles.tar'. If you are not sure of the exact file name, use globbing patterns, for example:

$ tar --list --file=bfiles.tar --wildcards '*b*'

will list all members whose name contains `b'. See section Wildcards Patterns and Matching, for a detailed discussion of globbing patterns and related tar command line options.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

Listing the Contents of a Stored Directory

To get information about the contents of an archived directory, use the directory name as a file name argument in conjunction with `--list' (`-t'). To find out file attributes, include the `--verbose' (`-v') option.

For example, to find out about files in the directory `practice', in the archive file `music.tar', type:

$ tar --list --verbose --file=music.tar practice

tar responds:

drwxrwxrwx myself/user       0 1990-05-31 21:49 practice/
-rw-r--r-- myself/user      42 1990-05-21 13:29 practice/blues
-rw-r--r-- myself/user      62 1990-05-23 10:55 practice/folk
-rw-r--r-- myself/user      40 1990-05-21 13:30 practice/jazz
-rw-r--r-- myself/user   10240 1990-05-31 21:49 practice/collection.tar

When you use a directory name as a file name argument, tar acts on all the files (including sub-directories) in that directory.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]

This document was generated on July, 28 2014 using texi2html 1.76.