Creating basic tar archives
Last revision July 20, 2004
Additional topics:
|
The simplest case uses this syntax:
tar c dirs_or_files
This writes the resulting archive file to the default tape interface and starts a new file at the beginning of the tape. The existing contents of the tape will be overwritten.
The problem with this simple tar command is that the default tape drive on pangea is the system backup tape unit. This backup unit is in the locked pangea computer room and may only be used by the root account to do system backups. So on pangea, at least, you must specify some other device for the output archive file, using the f option. Currently, there is no user-accessible tape drive on pangea, so you should specify an output disk file in the /scr1 temporary disk partition. You can then move the archive directly to another computer over the network.
The f option can be used with any of the tar operations: creating, listing, or extracting from an archive. You place the letter f immediately after the operation code on the command line. The next argument (leave a blank space) is then the device name or file pathname where the archive is to be created or (for listing and extracting) is currently located. This archive file pathname must come before the list of files to be archived. For example, to archive the gp111ins class directory to a file named gp111.tar in the /scr1 disk partition, you can use the commands:
cd ~gp111ins
tar cf /scr1/gp111.tar .
Notice the use of the period character (.) as the files argument in order to indicate the current directory. It is also customary, but not required, to use the .tar suffix on the output archive file name to make it clear that this is a tar format archive file.
You can write an archive to standard output (to pipe to another command), or read an archive from standard input, by using a single hyphen (-) character by itself as the pathname that follows the f option.
If using magnetic tape for your archive, you can put more than one archive file on the same tape if you use the mt command to first move the tape position past the files that already exist and then use tar to create a new archive at the end of the tape. But be careful to correctly space over the existing files or you may destroy them.
Any number of individual file names or entire directory trees can be listed as arguments and will all be packed into a single archive.