Others > Miscellaneous

How to extract a single directory from tar archive using command line



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 ..
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..

I think it need to be like this:

--- Code: ---tar -zxvf archive.tar mydirectorytoextract
--- End code ---

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.

 :)    :)

-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.

Glad you got it working. 

 :)    :)


[0] Message Index

Go to full version