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

2.5 Two Frequently Used Options

To understand how to run tar in the three operating modes listed previously, you also need to understand how to use two of the options to tar: ‘--file’ (which takes an archive file as an argument) and ‘--verbose’. (You are usually not required to specify either of these options when you run tar, but they can be very useful in making things more clear and helping you avoid errors.)


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

The ‘--file’ Option

--file=archive-name
-f archive-name

Specify the name of an archive file.

You can specify an argument for the ‘--file=archive-name’ (‘-f archive-name’) option whenever you use tar; this option determines the name of the archive file that tar will work on.

If you don’t specify this argument, then tar will examine the environment variable TAPE. If it is set, its value will be used as the archive name. Otherwise, tar will use the default archive, determined at compile time. Usually it is standard output or some physical tape drive attached to your machine (you can verify what the default is by running tar --show-defaults, see section Obtaining GNU tar default values). If there is no tape drive attached, or the default is not meaningful, then tar will print an error message. The error message might look roughly like one of the following:

tar: can't open /dev/rmt8 : No such device or address
tar: can't open /dev/rsmt0 : I/O error

To avoid confusion, we recommend that you always specify an archive file name by using ‘--file=archive-name’ (‘-f archive-name’) when writing your tar commands. For more information on using the ‘--file=archive-name’ (‘-f archive-name’) option, see Choosing and Naming Archive Files.


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

The ‘--verbose’ Option

--verbose
-v

Show the files being worked on as tar is running.

--verbose’ (‘-v’) shows details about the results of running tar. This can be especially useful when the results might not be obvious. For example, if you want to see the progress of tar as it writes files into the archive, you can use the ‘--verbose’ option. In the beginning, you may find it useful to use ‘--verbose’ at all times; when you are more accustomed to tar, you will likely want to use it at certain times but not at others. We will use ‘--verbose’ at times to help make something clear, and we will give many examples both using and not using ‘--verbose’ to show the differences.

Each instance of ‘--verbose’ on the command line increases the verbosity level by one, so if you need more details on the output, specify it twice.

When reading archives (‘--list’, ‘--extract’, ‘--diff’), tar by default prints only the names of the members being extracted. Using ‘--verbose’ will show a full, ls style member listing.

In contrast, when writing archives (‘--create’, ‘--append’, ‘--update’), tar does not print file names by default. So, a single ‘--verbose’ option shows the file names being added to the archive, while two ‘--verbose’ options enable the full listing.

For example, to create an archive in verbose mode:

$ tar -cvf afiles.tar apple angst aspic
apple
angst
aspic

Creating the same archive with the verbosity level 2 could give:

$ tar -cvvf afiles.tar apple angst aspic
-rw-r--r-- gray/staff    62373 2006-06-09 12:06 apple
-rw-r--r-- gray/staff    11481 2006-06-09 12:06 angst
-rw-r--r-- gray/staff    23152 2006-06-09 12:06 aspic

This works equally well using short or long forms of options. Using long forms, you would simply write out the mnemonic form of the option twice, like this:

$ tar --create --verbose --verbose …

Note that you must double the hyphens properly each time.

Later in the tutorial, we will give examples using ‘--verbose --verbose’.

The ‘--verbose’ option also enables several warning messages, that tar does not issue otherwise, such as the warning about record size being used (see section The Blocking Factor of an Archive), selecting the decompress program and the like. If these are of no interest to you, you can suppress them using the ‘--warning’ option after--verbose’, e.g.:

$ tar -c -v --warning=no-verbose -f afiles.tar apple angst aspic

See section verbose, for details.

The full output consists of six fields:

For example, here is an archive listing containing most of the special suffixes explained above:

V--------- 0/0            1536 2006-06-09 13:07 MyVolume--Volume Header--
-rw-r--r-- gray/staff   456783 2006-06-09 12:06 aspic--Continued at byte 32456--
-rw-r--r-- gray/staff    62373 2006-06-09 12:06 apple
lrwxrwxrwx gray/staff        0 2006-06-09 13:01 angst -> apple
-rw-r--r-- gray/staff    35793 2006-06-09 12:06 blues
hrw-r--r-- gray/staff        0 2006-06-09 12:06 music link to blues

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

Getting Help: Using the ‘--help’ Option

--help

The ‘--help’ option to tar prints out a very brief list of all operations and option available for the current version of tar available on your system.


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

This document was generated on August 23, 2023 using texi2html 5.0.