Your ads will be inserted here by
Easy AdSense.
Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.
I often have a batch of *.tgz tarballs lying around waiting for me to be unpacked. Often I want to unpack them into subdirectories, as not all of the tarballs contain subdirectories or they might even have conflicting filenames. The following little bash script does the trick (assuming you want to unpack all tarballs in your working directory):
#!/bin/bash for i in `ls *.tgz`; do DIRNAME=`(echo $i | sed "s/\.tgz//g")` if [ -d $DIRNAME ]; then echo "Warning, directory exists" elif [ -f $DIRNAME ]; then echo "Error $DIRNAME is file" else mkdir $DIRNAME fi cp $DIRNAME.tgz $DIRNAME cd $DIRNAME tar xf $DIRNAME.tgz rm -rf $DIRNAME.tgz cd .. done
Obviously you can easily tweak the script to accommodate for other formats, more sophisticated error checking… you name it.
Leave a Reply