FreeKB - TAR extract an archive
TAR - extract an archive

Let's say you have a tar archive that contains the following.

tar -tf example.tar
. . .


The tar command with the -x or --extract and -f or --file options will extract the contents of the tar archive. In this example, the contents of example.tar will be extracted into the present working directory. You will almost always want to also use the -p or --preserve-permissions flag, so that the file permissions are preserved.

tar -xpf example.tar


The -v or --verbose option can be used to display the files being extracted.

tar -xpvf example.tar
. . .


As an example, if your present working directory is /home/john.doe, following will be where the archive is extracted.



The  -C or --directory options can be used to extract the contents to a specific directory. In this example, both of these commands have the same result, where the contents of example.tar are extracted to the / directory.

tar -xpf example.tar --directory /
cd /; tar -cf example.tar


The -z option will be needed if the archive is gzip compressed.

tar -zxpf example.tar.gz


The -j option will be needed if the archive is bz2 compressed.

tar -jxpf example.tar.bz2


To extract a single file from the archive, include the file exactly as it is listed in the archive.

tar -xpf example.tar path/to/example.txt


The -C or --directory option can be used to extract the single file to a certain directory.

tar -xpf example.tar --directory /tmp path/to/example.txt

Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter de65b in the box below so that we can be sure you are a human.


Web design by yours truely - me, myself, and I   |   |