Showing posts with label untar. Show all posts
Showing posts with label untar. Show all posts

Monday, July 21, 2008

Untar a Single File

From time to time, I've had the need to extract a single file from a tar archive. How to do so is pretty poorly documented in the man page, but it's actually easy to do. If you have a tarball named "my.tar" with a group of files in it, and you want to extract "hello.txt", you would do the following:

tar -x hello.txt -vf my.tar

Before I extract anything from a tarball, I always preview it's contents to avoid "tarbombs" (tarballs that extract directly into the CWD).

tar -tvf my.tar

Or if it's gzipped:

tar tzvf my.tar.gz

Lastly, newer versions of Vim can browse a tarball out of the box and open any file contained within.

vim my.tar (displays a file browser)