Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Extract a folder from a tgz file

Posted on 2005-04-25
Medium Priority
Last Modified: 2012-06-21
I have a backup of my sever each night that creates a tgz file. In the file are many folders with many files. I wish to just extract one particular folder (it has thousands of text and pdf files in it ).

What is the syntax to extract just a folder of files and put it back in the correct place?

Thank you  
Question by:bin2003
  • 2
LVL 19

Expert Comment

ID: 13859015
Create a file which lists the necessary directory/directories you need to extract - be sure to include the wild card characters.

You can then use the file in the extraction process by specifying the --from-file= parameter:

tar -zxvf --from-file=myfileselection.txt mygzippedtarfile.tgz

Author Comment

ID: 13859077
Thank you. How does this know which folder to extract to? Do I have to extract to folder where I have the tgz file then copy/move them to correct folder afterwards?
LVL 19

Accepted Solution

Barthax earned 500 total points
ID: 13859889
It extracts to the relative path based on the current working directory, so if you are running tar from /home/myuser and you are extracting mypath/myfile from the tar, then it will be extracted to /home/myuser/mypath/myfile.
LVL 48

Expert Comment

ID: 13862974
Just do:

cd /
tar zxvf /path/to/backup.tgz path/to/folder/to/be/restored

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses

572 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question