Results 1 to 4 of 4

Thread: Selecting which files to extract from archive

  1. #1
    Join Date
    Feb 2007
    Beans
    13

    Selecting which files to extract from archive

    I need to extract some files from a number of large, compressed archives (.tgz). Just decompressing all the files would be easy but would result in huge disk space usage. Is there a way to tell gzip (or another utility) to only extract those files inside each .tgz file that have names starting with "a"?

  2. #2
    Join Date
    Jul 2010
    Beans
    21

    Re: Selecting which files to extract from archive

    http://www.gnu.org/software/tar/manual/tar.html#SEC26


    tl;dr version


    List files in collection.tar:

    Code:
    tar --list --file=collection.tar
    extract specific file "example.txt" from collection.tar:

    Code:
    tar --extract --file=collection.tar example.txt
    extract all files beginning with the letter "a" from collection.tar:

    Code:
    tar -x -f collection.tar --wildcards --no-anchored 'a*'
    Last edited by Morderwurst; June 8th, 2011 at 01:18 AM. Reason: Didn't address all of OPs question

  3. #3
    Join Date
    Feb 2007
    Location
    Romania
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Re: Selecting which files to extract from archive

    Code:
    cd /path/to/dir
    for file in *.tgz
    do
      tar xfvz "$file" --wildcards --no-anchored 'a*'
    done
    Where,
    • x: instructs tar to extract files.
    • f: specifies filename / tarball name.
    • v: Verbose (show progress while extracting files).
    • z: filter archive through gzip, use to decompress .gz files.
    • --wildcards: instructs tar to treat command line arguments as globbing patterns.
    • --no-anchored: informs it that the patterns apply to member names after any / delimiter.


    See:
    http://www.cyberciti.biz/faq/linux-u...pecific-files/

  4. #4
    Join Date
    Feb 2007
    Beans
    13

    Re: Selecting which files to extract from archive

    Thanks, sisco. That looks like it should work.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •