How to Uncompress Multiple Archives at Once

Compressed files are excellent for storing backups, sharing data, and creating archives of information. Normally, you can SSH into your server and extract files from a compressed archive with a single command. For more than one archive, you would normally have to uncompress each one separately.

There are a number of archive types that you will encounter on Unix and Linux servers. These include: ZIP (.zip), Gzip (.gz), Bzip2 (.bz2), Tar+Gzip (.tar.gz), and Tar+Bzip2 (.tar.bz2).

To unzip multiple .zip files, run the following command:

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

To uncompress multiple .gz files, type:

gunzip *.gz

To uncompress .bz2 files, type the following:

bunzip2 *.bz2

To uncompress .tar.gz files, type:

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

Finally, to uncompress tar.bz2 files, type this command string:

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

Uncompressing larger archives can take some time and system resources. If you have to extract a lot of data, you might want to consider doing it during low-traffic hours so that you do not take up resources your server can use for websites and/or databases. One important reason you might want to uncompress multiple archives is to test backups. Sometimes, a server may appear to properly perform automated backups, but once you actually uncompress the archives, you may find corrupt or missing data.