for tarfile in cc3m/*.tar; do dirname=$(basename "$tarfile" .tar) # Extracts the index from the tar file name mkdir -p "cc3m-images/$dirname" # Creates a directory with the index tar -xvf "$tarfile" -C "cc3m-images/$dirname" # Extracts the tar file into the created directory done