Showing posts with label extract. Show all posts
Showing posts with label extract. Show all posts

Tuesday, September 17, 2019

Testing Gzipped Tarball in Bash

Originally sourced from stack exchange. modified a bit:
https://unix.stackexchange.com/questions/129599/test-tar-file-integrity-in-bash

Modified from the source link above, the following command will iteratively test each .tgz file within the current directory for errors, and if any are detected, will report an error.

$ for i in *.tgz; do echo "Testing $i..."; if tar xOfz $i &> /dev/null;  then echo "Error with tarball $i"; fi; done


Options used:
 x  - Extract from archive
 O  - Write output to standard out instead of disk
 f  - Read input from a file
 z  - Tarball is compressed with Gzip (Some OSes may automatically detect Gzip and not need this option)
 &> /dev/null  -   Redirect both stdout and stderr to /dev/null

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