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
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
October 6th, 2008 at 5:07 am
Hello there,
After running the above command, I get the following errors:
ls: No match.
for: Command not found.
a: Undefined variable.
October 6th, 2008 at 8:31 am
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
February 8th, 2011 at 5:03 pm
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