Selectively Extracting Files or Directories from a Tarball File
If you use Tarball or Gzip file archives for storing your data, occasionally you may need to extract only a few select files or directories, rather than the entire archive file’s contents. Many people waste time, CPU, and drive space extracting the entire archive only to get access to a few of the contents, then to discard the rest of the data.
Why should one wait on files to extract that will just be deleted immediately after, without being used? Thanks to the great minds behind the tar application for Unix and Linux; we have been privileged with a solution. A little-known time saving tip is that extracting only specified directories or files from a tar gzip file is possible.
The Command; Example and Implementation
In order to extract specific files or directories from a tarball tar gzip file archive, you will need to have the name of the initial archive, as well as the path to the file or files, and directory or directories inside of the archive which you specifically wish to extract.
For example, you have a archive tarball file named backup-2010.03.12.tar.gz that contains the following directories; not all of which you wish to extract.
home/user1
home/user2
home/user3
To extract only the directory user2, you need to run the subsequent command:
The command template is as follows:
To extract multiple files or directories, simply append to the template the additional directories or files you wish to extract. For example:
Tips:
If you are wanting more clarification on the command line syntax; you may quickly view the tar command line switches and options from your shell by typing the following:
Note: there are two dashes before “help”.
Additionally, you may check the Manual “man” pages for tar. The manual pages provide an in-depth explanation for each command and switch for the tar application. You may access the tar man pages by typing in the following:
When you’re done reading the manual “man” pages, type or press q to the manual “man” page display interface.
You can follow any responses to this entry through the RSS 2.0 feed. You can skip to the end and leave a response. Pinging is currently not allowed.

















