How To Extract a Single File / Directory from Tarball Archive

by Vivek Gite on April 29, 2008 · 2 comments

Q. How do I extract a single file or directory form a tarball under UNIX / Linux shell prompt? How do I restore a single file from /dev/st0 tape device?

A. tar command allows to extract a single file or directory using the following format. It works under UNIX, Linux, and BSD operating systems.

tar xvf /dev/st0 filename
tar xvf /dev/st0 directory-name
tar xvf mytar.ball.tar filename
tar -zxvf mytar.ball.tar.gz directory-name

Extract file to /tmp directory
tar -zxvf mytar.ball.tar.gz -C /tmp filename
tar -zxvf mytar.ball.tar.gz -C /tmp dir-name

Read tar man page for more information:
man tar

Featured Articles:

Share this with other sys admins!
Facebook it - Tweet it - Print it -

{ 2 comments… read them below or add one }

1 Raju Kumar August 25, 2009

Hi,

I am running the same command to extract a directory from the tape backup. But its taking lot of time. So I have cancelled it

Could you tell me will it take time or else there is any other command which execute faster.

Thanks
Raju

Reply

2 David the Short September 15, 2011

Raju,
tar will take time, even when extracting a single file it will take a long time to complete if the tarball is big.
I know of nothing faster than tar to extract from a tar. Maybe just background the process and wait.
Cheers

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 15 + 13 ?
Please leave these two fields as-is:
Solve the simple math so we know that you are a human and not a bot.




Previous post:

Next post: