Note that the
cvf
options must be supplied as a single group, with no spaces in between. A preceding hyphen (
-
) is allowed but not required .
Specifying options with tar
The tar
command is unusual because you do not need to put a hyphen (-) before the options. In the earliest UNIX versions, you were not supposed to use a -
before
the options; otherwise, you would generate an error. As UNIX evolved, users felt that the commands needed to be more consistent. Newer versions of UNIX therefore began allowing the -
with tar
options, but it wasn’t required.
The tar
command allows a hyphen only before the first option. In addition, all options must be listed together, without spaces between them. The following table summarizes the basic syntax for the tar
command. Notice that the first example is incorrect because it contains multiple hyphens and includes spaces between the options.
Command | Comment |
tar –c –v –f bigfile.tar my_dir | Not allowed |
tar –cvf bigfile.tar my_dir | Allowed |
tar cvf bigfile.tar my_dir | Allowed |
The
c
option stands for
create. When you create an archive,
c
is required and must go first. The
v
stands for
verbose. It’s optional but recommended. The
v
causes
tar
to list file names as they are being
archived. The
f
option is used along with the
archive
argument, which is explained below.