Skip to content

Instantly share code, notes, and snippets.

@aheissenberger
Created June 26, 2017 10:06
Show Gist options
  • Save aheissenberger/bc07a017fa4434011125dadea597614e to your computer and use it in GitHub Desktop.
Save aheissenberger/bc07a017fa4434011125dadea597614e to your computer and use it in GitHub Desktop.
Convert a zip to a bzip2 compressed tar (.tbz)
#!/bin/bash
# Usage: ziptotar.sh <ZIP name>
if [ -z $1 ] || [ "$1" == "-h" ] || [ "$1" == "--help" ];then
echo "Convert a zip to a bzip2 compressed tar (.tbz)"
echo "ziptotar.sh <ZIP name>"
exit
fi
for file in "$@"
do
if [ ! -f "$file" ];then
echo "No file! $file"
continue
fi
tmpdir=`mktemp -d`
#Copy the zip to the temporary directory
cp "$file" $tmpdir/
#Unzip
(cd $tmpdir && unzip -q "$file")
#Remove the original zipfile because we don't want that to be tar'd
rm "$tmpdir/$file"
#Tar the files
outfilename=$(echo "$file" | rev | cut -d. -f2- | rev).tbz
(cd $tmpdir && tar cjf "$outfilename" *)
mv "$tmpdir/$outfilename" .
#Remove the temporary directory
rm -rf $tmpdir
#Print what we did
echo "Converted $file to $outfilename"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment