Extract a folder from a tgz file

Posted on 2005-04-25
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
    LVL 19

    Expert Comment

    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

    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

    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

    Just do:

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

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap ( Version 1.2 2.      Jpcap( Version 0.6 Prerequisite: 1.      GCC …
    FreeBSD on EC2 FreeBSD ( is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
    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…
    In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

    755 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now