Friday, August 8, 2014

Extract a list of tarballs from the pwd into their own separate folders


  •  Extract all .tar.gz files residing in current dir into their own folders based upon the tarball’s filename.
  • Recommended naming convention for .tar.gz file is:  hostname-otherdetails.tar.gz (NOTE:  required details is the first hyphen which is used to separate the fields, using the first field as the target directory where the corresponding tarball will be extracted to
  • To change the parsing separating character, change the hyphen reference in the cut -d portion of the statement to another character, such as an underscore— For example,  cut -d ‘_’ -f1 



$ for i in *.tar.gz; do mkdir `echo $i | cut -d '-' -f1`; tar xvfz $i -C `echo $i | cut -d '-' -f1`; done


No comments:

Post a Comment