Linux - Extract all tar files in a directory

Multiple tar files in a directory and want to extract them all?

This works in the Bash shell:

for a in `ls -1 *.tar.gz`; do tar -zxvf $a; done

3 Responses to “Linux - Extract all tar files in a directory”

  1. tamon Says:

    Hello there,

    After running the above command, I get the following errors:

    ls: No match.
    for: Command not found.
    a: Undefined variable.

  2. Bill Gross Says:

    Tamon;

    Make sure you have the correct apostrophy marks. They must be the “backward” apostrophy. On my MB it’s above the tab key, on my Dell it’s also above the tab key.

    Bill

  3. Darren Says:

    It’s great that this comes up as one of the first results in Google - saved me trying to work it out myself! I had to make a slight change to the code because my gzipped tar files had .tgz file extensions, not tar.gz. I used…

    for a in `ls -1 *.tgz`; do tar -zxvf $a; done

Leave a Reply