Skip to content

Instantly share code, notes, and snippets.

@nyg
Created April 2, 2019 11:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nyg/3e989e4ad3379e80c08d2900668693fd to your computer and use it in GitHub Desktop.
Save nyg/3e989e4ad3379e80c08d2900668693fd to your computer and use it in GitHub Desktop.
Script to recursively extract archives
#!/usr/bin/env bash
# Usage: /absolute/path/to/script.sh /absolute/path/to/folder/with/archive
for file in $1/* ; do
if [ -f "$file" ] ; then
echo Found file: $file
info=$(file $file | tr '[:upper:]' '[:lower:]')
case $info in
*bzip2*)
echo found bzip2
mkdir $1/a
cd $1/a
bzip2 -kd $file -c > archive
/Users/user/Downloads/auto_extract.sh $1/a
;;
*gz*)
echo found gz
mkdir $1/a
cd $1/a
gunzip -d $file -c > archive
/Users/user/Downloads/auto_extract.sh $1/a
;;
*zip*)
echo zip
unzip $file -d $1/a
/Users/user/Downloads/auto_extract.sh $1/a
;;
*)
echo [Unknown] $info
exit 1
esac
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment