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:
blues folk jazz
The archive bfiles.tar would list as follows:
./birds baboon ./box
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 absolute, 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 cfv archive /etc/mail tar: Removing leading `/' from member names /etc/mail/ /etc/mail/sendmail.cf /etc/mail/aliases $ tar tf archive etc/mail/ etc/mail/sendmail.cf etc/mail/aliases
This default behavior can sometimes be inconvenient. You can force GNU tar show member names when creating archive by supplying --show-stored-names option.
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 paths, file names 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 wildcards, for a detailed discussion of globbing patterns and related tar command line options.