March 29, 2024, 07:57:51 AM

News : LinuxSolved.com Linux Help Community Forum..


Author Topic: How to extract a single directory from tar archive using command line  (Read 10727 times)

Offline keen_prat

  • Linux Noob !
  • *
  • Posts: 21
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..

Offline dalek

  • LST CareTaker
  • Crescent
  • *****
  • Posts: 243
Re: How to extract a single directory from tar archive using command line
« Reply #1 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.

 :)    :)

Offline keen_prat

  • Linux Noob !
  • *
  • Posts: 21
Re: How to extract a single directory from tar archive using command line
« Reply #2 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.

Offline dalek

  • LST CareTaker
  • Crescent
  • *****
  • Posts: 243
Re: How to extract a single directory from tar archive using command line
« Reply #3 on: December 07, 2012, 07:26:07 AM »
Glad you got it working. 

 :)    :)