Skip to content

Instantly share code, notes, and snippets.

@4piu
Created October 16, 2019 15:39
Show Gist options
  • Save 4piu/af0bdf56f7ac57ae52508d0c61d8486d to your computer and use it in GitHub Desktop.
Save 4piu/af0bdf56f7ac57ae52508d0c61d8486d to your computer and use it in GitHub Desktop.
Convert tar to zip
#!/bin/bash
# Warning! /tmp is used to store the extracted file
TMP='/tmp/tar2zip/'
IFS=$(echo -en "\n\b")
if [ $# == 0 ]
then
set -- `ls *.{tar,gz,gz2,bz,bz2,Z} 2> /dev/null`
fi
mkdir -p ${TMP}
rm ${TMP}/* -r 2> /dev/null
for file in $@
do
echo "Extracting: ${file}"
tar -xaf ${file} -C ${TMP} --one-top-level ${TAR_ARGS}
if [ $? != 0 ]
then
echo "Error extracting"
continue
fi
echo "Compressing to zip"
zip -rjq9 `echo ${file} | cut -d. -f1`.zip ${TMP}/* ${ZIP_ARGS}
if [ $? != 0 ]
then
echo "Error compressing"
continue
fi
echo "Cleaning up"
rm ${TMP}/* -r
rm ${file}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment