manpagez: man pages & more
info tar
Home | html | info | man
[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.6.2 Creating the Archive

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. You could also say:

$ tar blues --create folk --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 November 1, 2013 using texi2html 5.0.

© manpagez.com 2000-2024
Individual documents may contain additional copyright information.