[GNU/Linux] How to extract a single file from a tar archive?

| | 1 min read

If you are using GNU/Linux, you are likely to be familiar with the command line, usually Bash, which of course means that you would be working with tar archives (tape archives). The need to extract a single file from a tar archive/file is a common situation faced by bash users. Read on to know how to do it.

The following commands will extract the single file from the tar, tar.gz, tar.bz2 files.

To extract a single file from a tar file :

 tar -xvf filename.tar filename

To extract a single file from a tar.gz file :

tar -xvf filename.tar.gz filename

To extract a single file from a tar.bz2 file :

 tar -xvf filename.tar.bz2 filename 

Here 'filename' refers to the single file that is required from the large tar, tar.gz or tar.bz2 file. Each of these commands will extract the single file needed from the large file.