Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Mail Systems
Eclipse Documentation

How To Guides
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Problem Solutions
Privacy Policy




Next: , Previous: prepare for examples, Up: create

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 part of the command which says, --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 short 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). Now that they are in the archive, they are called archive members, not files. (see 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 append.

  Published under the terms of the GNU General Public License Design by Interspire