-   Linux - General (
-   -   How to extract specific directory from a TAR file? (

Micro420 04-17-2007 07:59 PM

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:


cd /home/theboss
tar -tf /backups/filename.tar.gz | grep /home/theboss | xarg tar -zxf filename.tar.gz

Will this work?

Quakeboy02 04-17-2007 08:03 PM

have you tried using file-roller?

Micro420 04-17-2007 08:05 PM

There is no GUI on this server.

Is this correct?


cd /home/theboss
tar -zxf /backups/filename.tar.gz /home/theboss

I'm assuming that is:
tar -options <source> <directory-to-extract-from-tar-file>

Quakeboy02 04-17-2007 09:18 PM


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.

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.

Sorry, that should be:

tar -ztvf /backups/filename.tar.gz /home/theboss

Micro420 04-18-2007 12:04 AM

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.

All times are GMT -5. The time now is 03:48 PM.