How to Extract Specific Files from a Tarball

One of the most common methods of archiving files on a Linux or Unix server is called tar. Tar can store any number of files in individual archives and can be used in conjunction with compression programs like gzip and bzip2. Normally, when you want to extract files from a tarball, you simply run the tar command and extract them all. But if you only want to extract one file, you will need to learn a different command string.

First, you need to list the contents and exact path to the file within the archive using the “t” option. For example:

$ tar -ztvf innotop-1.9.0.tar.gz

Find the file you want within the output:

-rw-rw-r– baron/Domain Users 584 2009-02-23 22:28 innotop-1.9.0/Makefile.PL

Then, extract the single file simply by attaching the path to the end of the line and switching to the “x” option:

$ tar -zxvf innotop-1.9.0.tar.gz innotop-1.9.0/Makefile.PL

If you ever need to extract certain file types, you can use the “–wildcards” option. For example, to extract all html files type:

$ tar -xf archive.tar –wildcards –no-anchored ‘*.html’

It is truly that simple. For more information about ways to use tar, type “man tar” from the command line or visit the man page online.