How to extract multiple tar ball (*.tar.gz) files in directory on Linux or Unix

Here’s how you can extract multiple tar.gz files in a directory on Linux or Unix:

  1. Navigate to the directory containing the tar.gz files:
cd /path/to/directory
  1. Use the following command to extract all tar.gz files in the directory:
for i in *.tar.gz; do tar xvf "$i"; done

This command will extract each tar.gz file in the directory one by one. The x option tells tar to extract the contents of the archive, the v option makes the extraction process verbose (displays the files as they are extracted), and the f option specifies the file to be extracted.

If you want to extract all files to a specific directory, you can use the following command:

for i in *.tar.gz; do tar xvf "$i" -C /path/to/destination; done

Replace /path/to/destination with the path to the directory where you want to extract the files.

Leave a Comment