[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
To place the files ‘blues’, ‘folk’, and ‘jazz’ into an archive named ‘collection.tar’, use the following command:
$ tar --create --file=collection.tar blues folk jazz
The order of the arguments is not very important, when using long option forms, however you should always remember to use option as the first argument to tar. For example, the following is wrong:
$ tar blues -c folk -f collection.tar jazz tar: -c: Invalid blocking factor Try 'tar --help' or 'tar --usage' for more information.
The error message is produced because tar
always treats its
first argument as an option (or cluster of options), even if it does
not start with dash. This is traditional or old option
style, called so because all implementations of tar
have
used it since the very inception of the tar archiver in 1970s. This
option style will be explained later (see section Old Option Style), for now
just remember to always place option as the first argument.
That being said, you could issue the following command:
$ tar --create folk blues --file=collection.tar jazz
However, you can see that this order is harder to understand; this is
why we will list the arguments in the order that makes the commands
easiest to understand (and we encourage you to do the same when you use
tar
, to avoid errors).
Note that the sequence ‘--file=collection.tar’ is considered to be one argument. If you substituted any other string of characters for collection.tar, then that string would become the name of the archive file you create.
The order of the options becomes more important when you begin to use short forms. With short forms, if you type commands in the wrong order (even if you type them correctly in all other ways), you may end up with results you don’t expect. For this reason, it is a good idea to get into the habit of typing options in the order that makes inherent sense. See section Short Forms with ‘create’, for more information on this.
In this example, you type the command as shown above: ‘--create’
is the operation which creates the new archive
(‘collection.tar’), and ‘--file’ is the option which lets
you give it the name you chose. The files, ‘blues’, ‘folk’,
and ‘jazz’, are now members of the archive, ‘collection.tar’
(they are file name arguments to the ‘--create’ operation.
See section Choosing Files and Names for tar
, for the detailed discussion on these.) Now that they are
in the archive, they are called archive members, not files.
(see section members).
When you create an archive, you must specify which files you
want placed in the archive. If you do not specify any archive
members, GNU tar
will complain.
If you now list the contents of the working directory (ls
), you will
find the archive file listed as well as the files you saw previously:
blues folk jazz collection.tar
Creating the archive ‘collection.tar’ did not destroy the copies of the files in the directory.
Keep in mind that if you don’t indicate an operation, tar
will not
run and will prompt you for one. If you don’t name any files, tar
will complain. You must have write access to the working directory,
or else you will not be able to create an archive in that directory.
Caution: Do not attempt to use ‘--create’ (‘-c’) to add files to an existing archive; it will delete the archive and write a new one. Use ‘--append’ (‘-r’) instead. See section How to Add Files to Existing Archives: ‘--append’.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated on August 23, 2023 using texi2html 5.0.