Investigating the Joy of Listing Tar Archives
Being able to list the contents of a tar archive is an essential part of any backup plan. It gives you the confidence to know what you think is in the archive matches the actual archive contents. We have already seen that we are able to list the archive contents with the option –list or the short form of -t. In the last clip we looked at creating archives we can now move onto listing tar archives.
Remember that -t is to list an archive and -T is used as the short form of –files-from
We will review these but we shall also take the opportunity to introduce you to the –verbose options or -v when both listing tar archives and creating them.
In listing an archive we are able to see the archive contents and it’s label should it have been set. So far, we have not set the label of an archive but we shall later.
$ tar --list --file=my.tar etc/hosts etc/services ...
The output from the command will list the file names. These names lack a leading / so are relative to the current directory. This is only important when perfoming the restore as it illustrates where the file will be restored too. When creating an archive we can specify to maintain the full path with the –absolute-names or -P option. Again, this is a subject for later learning.
If we want a little more detail of the archive contents we will make use of the –verbose option, or it’s short form of -v. On using either of thse options we have more of the file details being printed similar to a long listing with the command ls.
$ tar --list --verbose --file=my.tar -rw-r--r-- root/root 240 2018-01-10 16:36 etc/hosts -rw-r--r-- root/root 19605 2014-10-25 07:16 etc/services ...
The options –verbose can be applied multiple times to increase the verbosity of the output. The listing, though, only accepts the single –verbose option, increasing the verbosity has no effect but does not produce an error. When creating an archive, for example, a single –verbose option will list the file names being backed up; whereas a double dose of –-verbose will list the files with their details as we see here when used with –list and a single –verbose.
Let’s quickly review –create and the use of –verbose:
Example 1 using no verbosity does not list file names:
$ tar --create --file=my.tar /etc/hosts /etc/services tar: Removing leading `/' from member names
Example 2 a single verbose option will list file names that are archived
tar --create --verbose --file=my.tar /etc/hosts /etc/services tar: Removing leading `/' from member names /etc/hosts /etc/services
Example 3 using a double verbose option will list file names that are archived along with the file details
tar --create --verbose --verbose --file=my.tar /etc/hosts /etc/services tar: Removing leading `/' from member names -rw-r--r-- root/root 240 2018-01-10 16:36 /etc/hosts -rw-r--r-- root/root 19605 2014-10-25 07:16 /etc/services
We have now covered the basics of listing archive contents so we can move onto restoring archives in the next lesson. The video follows: