1. Paste the following code to file tarsubdir.sh:
#!/bin/sh #usage: # nameOfScript myArchive.tar.gz # nameOfScript myArchive.gz # nameOfScript myArchive.tar # # Result: # myArchive //folder fileName="${1%.*}" #extracted filename echo "file name is: $fileName" trailingExtension="${fileName##*.}" if [ "$trailingExtension" == "tar" ] then fileName="${fileName%.*}" echo "new file name is: $fileName" fi echo "now file name is: $fileName" mkdir "$fileName" tar -xf "$1" --strip-components=0 -C "$fileName"2. Paste the following code to another file untarall.sh:
#!/bin/sh for file in *.tar do bash ./tarsubdir.sh "$file" done3. Run from the bash prompt:
bash ./untarall.sh