Go to the previous, next section.

Extract Files from an Archive into Your Current Directory

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

Obviously, the ultimate goal of tar users is to eventually get their files back. To do this, use the `--extract' (`-x') or `--get' operation. `--extract' (`-x') can be used to retrieve individual files from an archive, or can be used to write all the files in the archive back into the file system.

In the previous example you concatenated two archives, `music', and `practice/records'. To now retrieve the complete contents of `music' (the target file in the concatenation process), you would, from the home directory:

% tar --extract --file=music
tar: Could not make directory practice : File exists

Because the files stored originally in `music' were stored as files in a subdirectory (not as files in the working directory), they are stored in the archive with a leading directory name---tar, in restoring them, has tried to recreate that directory and failed: the directory already exists. The extraction has not been aborted, however. If you now change into the `practice' directory and generate a directory listing, you will find that `jazz', which we removed in an earlier example, has been resurrected.

% cd practice
% ls
blues	   classical  folk	 jazz	    records    rock

If you look more closely at the files in the directory, however, you will find that `blues' and `folk' are, in fact, the original versions of the file, which were stored in `music' at the beginning of the tutorial. tar, in extracting the original files from `music', has overwritten the existing files in the file system.

While the newer versions of the files were stored in `records' above, they can no longer be extracted from it. `records' too was archived by tar when the `practice' directory was stored in the archive file `music', and was restored to its older incarnation when the files in `practice' were overwritten. However, the newer version of `records' was concatenated with `music'. The contents of the newer version of `records', therefore, should have been extracted when all the contents of `music' were extracted. They were. tar has restored them into the working directory using the names with which they were originally stored. Because they were originally stored as part of `records', in the `practice' directory, they had no preceeding directory stored as part of their file names. To find the latest versions of `blues', `folk', `jazz', `rock' and `classical', look in your home directory.

You may wish to restore the files in your `practice' directory to their last state before we extracted the files from `music'. Rather than moving the files from your home directory to the `practice' subdirectory, you can run the same extraction procedure as above using the `practice' subdirectory as your working directory:

% cd practice
% tar --extract --verbose --file=~/music
practice/
practice/blues
practice/folk
practice/jazz
practice/records
blues
folk
jazz
blues
rock
blues
classical
%

If you now examine the files in the practice directory, you will find that the files have been restored to their previous, newer, states. The old versions of the files, which were stored in `music' with a preceeding directory name, have been written into a newly created subdirectory under the working directory (which is your `practice' subdirectory). The new subdirectory is also called `practice'.

Go to the previous, next section.