How to extract a specific file from gzip compressed archive tarball

In order to extract a specific file from gzip compressed archive tarball you first need to know the full path to this file. Consider a following example.

$ tar tzf to-gzip.tar.gz
to-gzip/
to-gzip/file10.txt
to-gzip/file9.txt
to-gzip/file8.txt
to-gzip/file7.txt
to-gzip/file6.txt
to-gzip/file5.txt
to-gzip/file4.txt
to-gzip/file3.txt
to-gzip/file2.txt
to-gzip/file1.txt



In the above example we have used t command to list all files contained by to-gzip.tar.gz gzip archive. The output as a full path to all files in this archive. Next, we can use this path to extract any file. For example let’s extract file2.txt from this archive:

$ tar xvzf to-gzip.tar.gz to-gzip/file2.txt
to-gzip/file2.txt


Comments and Discussions
Linux Forum