Uncompress multiple .zip .gz or .bz2


for file in *.zip; do unzip "${file}"; done


gunzip *.gz


bunzip2 *.bz2


for file in *.tar.gz; do tar zxf "${file}"; done


for file in *.tar.bz2; do tar jxf "${file}"; done

Shell script usage

If you use one of the snippets that uses a for loop in a script with an arbitrary number of archives, you may want to set the shell to use "nullglobs". For instance, normally *.tar.gz will evaluate to *.tar.gz when no files were found that match this wildcard, rather than evaluating to an empty string. As a result 'tar' is executed with this string as a parameter. To avoid this, you can request that the shell uses nullglobs with:

shopt -s nullglob

If no matches were found, the shell will return an empty string, and the for loop is terminated.

TipsAndTricks/UncompressMultipleFiles (last edited 2008-04-17 21:55:47 by TimVerhoeven)