Linux Forums - Linux Help,Advice & support community:LinuxSolved.com

Others => Miscellaneous => Topic started by: keen_prat on December 07, 2012, 06:44:28 AM

Title: How to extract a single directory from tar archive using command line
Post by: keen_prat on December 07, 2012, 06:44:28 AM
Hi

I am dealing with some large files and I need to extract only particular directly using command line and I am doing it like following:

First I finding all files are there in the tar file ..
like
tar -tf archive.tar

then when I confirmed its there, I gave command

tar -xvf archive.tar mydirectorytoextract

But it is giving error that its not there in archive, I have used similar technique to extract file but directory is not extracting.. help please..
Title: Re: How to extract a single directory from tar archive using command line
Post by: dalek on December 07, 2012, 07:05:25 AM
I think it need to be like this:

Code: [Select]
tar -zxvf archive.tar mydirectorytoextract
You have the order correct but I think you may need the -z option.  Watch that -f tho.  When you use it, it has to be right before the file name, either as a separate option or on the end like you have them.  I ran into that a few times myself.  Also, I read somewhere that you have to put the path to the file you want to extract too.  If I backup /home and then want to extract /home/dale/Desktop then it would be -f /home/dale/Desktop for tar to find the file.  If -z doesn't help, try checking the path.  Maybe it needs that.

Hope that helps.

 :)    :)
Title: Re: How to extract a single directory from tar archive using command line
Post by: keen_prat on December 07, 2012, 07:10:50 AM
-z is now deprecated but I think I found the solution, I was just trying and it was indeed path issue. I gave it like ./directory-name (as it was in root of archive) and it did the job.
Title: Re: How to extract a single directory from tar archive using command line
Post by: dalek on December 07, 2012, 07:26:07 AM
Glad you got it working. 

 :)    :)