The tar command is designed to combine multiple files together into a single archive.
In this Linux quick tip we will learn to extract a single file from a tarball archive using the tar command.
For this example we will use my Pink Floyd mp3 collection. I used tar to archive my songs so I can move them to my new machine. Right now I only want to extract the song “Learning to Fly” from the archive.
We will need to know the exact name of the file. We can list the files in a tar archive using the following command.
tar -tvf filename.tar
Here is an example:
$ tar -tvf Floyd.tar
-rw-rw-r-- savona/savona 432516 2012-01-05 14:49 Echoes.mp3
-rw-rw-r-- savona/savona 837292 2012-01-05 14:49 Goodbye_Blue_Sky.mp3
-rw-rw-r-- savona/savona 748479 2012-01-05 14:49 Green_Is_The_Colour.mp3
-rw-rw-r-- savona/savona 3455103 2012-01-05 14:49 Learning_To_Fly.mp3
-rw-rw-r-- savona/savona 234426 2012-01-05 14:49 Obscured_By_Clouds.mp3
Now we can see the filename for Learning to Fly is “Learning_To_Fly.mp3”. Let’s extract that one song with the following command:
tar xvf filename.tar file_to_extract
Example:
$ tar xvf Floyd.tar Learning_To_Fly.mp3
Learning_To_Fly.mp3
Resources:
Join Our Newsletter
Categories
- Bash Scripting (17)
- Basic Commands (50)
- Featured (7)
- Just for Fun (5)
- Linux Quick Tips (98)
- Linux Tutorials (65)
- Miscellaneous (15)
- Network Tools (6)
- Reviews (2)
- Security (32)
- Uncategorized (1)