Go to the previous, next section.

Extracting Directories

(This message will disappear, once this node revised.)

To extract a directory and all the files it contains, use the directory's name as a file name argument in conjunction with `tar +extract'. Remember--tar stores and extracts file names relative to the working directory.

In a previous example you stored the directory `~/practice' in the archive file `~/music'. If you delete the contents of `practice', you can restore them using tar.

First, change into the `practice' subdirectory (`cd ~/practice'). Then, remove all the files in `~/practice' (`rm *'). If you list the contents of the directory, you should now see that it is empty:

%ls
%

Let's try to restore the contents of `practice' by extracting them from the archive file `~/music':

tar --extract --file=~/music practice

Now, list the contents of `practice' again:

%ls
practice

What happened to the files? When you created `~/music', your working directory was your home directory. When you extracted `~/music', your working directory was `~/practice'. tar stored the files in `practice' relative to your home directory, and then extracted them relative to `~/practice'. The files are now in a new subdirectory, called `~/practice/practice'.

To restore your files to their old positions, delete the new directory and its contents, and then redo the example above with your home directory as the working directory:

% rm ~/practice/practice/*
% rmdir practice
% cd ..
% tar --extract --file=music practice

(tar will report that it is unable to create the directory `~/practice' because it already exists. This will not effect the extraction of the other archive members.)

Go to the previous, next section.