tar c project
A similar way to specify the same directory is:
tar c ./project
If you are currently in the directory you want archived, you can type:
tar c .
Another way to archive the current directory is to type:
tar c *
Here, the shell expands the
to the files in the current directory.
However, it does not match files starting with a
which is why the previous technique is preferred.
This causes a problem when restoring a directory from a
You may not know if an archive was created using
or the directory name.
I always check the names of the files before restoring an archive:
If the archive loads the files into the current directory, I create a new directory, change to it, and extract the files.
If the archive restores the directory by name, then I restore the files into the current directory.
If you want to restore a single file, get the pathname
of the file as
knows it, using the
You must specify the exact filename, because
are not the same.
You can combine these two steps into one command
by using [this may run very slowly-JP ]:
tar xvf /dev/rst0 `tar tf /dev/rst0 | grep
Whenever you use tar to restore a directory, you must always specify some filename. If none is specified, no files are restored.
There is still the problem of restoring a directory whose pathname starts with / (slash). Because tar restores a file to the pathname specified in the archive, you cannot change where the file will be restored. The danger is that either you may overwrite some existing files or you will not be able to restore the files because you don't have permission.
You can ask the system administrator to rename a directory and temporarily create a symbolic link pointing to a directory where you can restore the files. Other solutions exist, including editing the tar archive and creating a new directory structure with a C program executing the chroot(2) system call. Another solution is to use the version from thethat allows you to remap pathnames starting with / (slash). It also allows you to create archives that are too large for a single tape, incremental archives, and a dozen other advantages. This freely available version of tar is also called . (It's on the disc.)
But the best solution is to never create an archive
of a directory that starts with
Because of its nature, it is difficult to read fixed-size blocks over a network. This is why tar uses the B flag to force it to read from the pipe until a block is completely filled. [Some versions of tar, like the one fromon the CD-ROM, handle remote drives automatically. -JIK ]