How to extract specific directory from a TAR file?
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: Mac OS X Leopard 10.6.2, Windows 2003 Server/Vista/7/XP/2000/NT/98, Ubuntux64, CentOS4.8/5.4
Posts: 2,986
Rep:
How to extract specific directory from a TAR file?
My boss deleted her folder off the server. I make backups so I'm clear, however, I cannot find out how from the MAN pages and Google how to ONLY extract from the tar file her directory. All I can find are how to extract a specific file to an individual directory. Not what I want.
I'm thinking maybe:
Code:
cd /home/theboss
tar -tf /backups/filename.tar.gz | grep /home/theboss | xarg tar -zxf filename.tar.gz
cd /home/theboss
tar -zxf /backups/filename.tar.gz /home/theboss
I think this will give you /home/theboss/home/theboss/..., won't it? I believe that you need to run the extraction from the root directory used for creation of the tar file. IOW, if you were actually IN /home/theboss when you ran tar, then, yes, go to /home/theboss. But, your tar won't actually have anything in it starting with /home/theboss, will it?
If this was a full backup, cd to "/". You can do a sort of trial run by running the following and seeing the full pathnames of what's in tar, if you don't already know.
Code:
oops, deleted see edit below
You can also go to some temporary directory and run your extract to see what gets created under that temp directory.
Edit:
Sorry, that should be:
Code:
tar -ztvf /backups/filename.tar.gz /home/theboss
Last edited by Quakeboy02; 04-17-2007 at 09:33 PM.
Distribution: Mac OS X Leopard 10.6.2, Windows 2003 Server/Vista/7/XP/2000/NT/98, Ubuntux64, CentOS4.8/5.4
Posts: 2,986
Original Poster
Rep:
Thanks for the suggestions, Quakeboy02. Unfortunately I have to get the data back up by the morning when my boss returns to the office so I can't test your method. I have the files remotely stored so I decided to just use scp. It should be done in a few hours (1.5GB). I could do a complete untar of the backup, but I don't want to risk it and mess up other files and people's directory by overwriting files. The server is on 24/7 and in use throughout the evening.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.