Skip to content

Instantly share code, notes, and snippets.

@jlgarridol
Last active February 24, 2016 20:15
Show Gist options
  • Save jlgarridol/f3d6528c432a9ead4e34 to your computer and use it in GitHub Desktop.
Save jlgarridol/f3d6528c432a9ead4e34 to your computer and use it in GitHub Desktop.
A simple script to zip and unzip with tar
#!/bin/sh
#Author: José Luis Garrido Labrador (JoseluCross)
#Organitation: JKA Network
#Original http://mirror.jkanetwork.com/Scripts/zipTar.sh
#Licence: CC-BY-SA
#Version: v1.3
#This script help the user to zip and unzip in differents formats
#The version 1.1 include the format .tbz2
#The version 1.2 allow unzip write ($1) the format too
#The version 1.3 now the script run in many other GNU/Linux destributions
echo "Choose, zip (1) or unzip (2)"
read option
if [ $option -ne 1 ] && [ $option -ne 2 ];then
echo Incorrect option
exit
fi
echo Choose the format, 1 tar, 2 tar.gz, 3 tar.bz2, 4 .tbz2
read format
if [ $option -eq 2 ];then
if [ $format -eq 1 ];then
tar xf $1
echo It has been unzipped $1.tar
elif [ $format -eq 2 ];then
tar xzf $1
echo It has been unzipped $1.tar.gz
elif [ $format -eq 3 ];then
tar xjf $1
echo It has been unzipped $1.tar.bz2
elif [ $format -eq 4 ];then
tar xvjf $1
echo It has been unzipped $1.tbz2
else
echo Incorrect format, restart the script
exit
fi
elif [ $option -eq 1 ];then
if [ $format -eq 1 ];then
tar cf $1.tar $1
echo It has been zipped $1 in $1.tar
elif [ $format -eq 2 ];then
tar czf $1.tar.gz $1
echo It has been zipped $1 in $1.tar.gz
elif [ $format -eq 3 ];then
tar cjf $1.tar.bz2 $1
echo It has been zipped $1 in $1.tar.bz2
elif [ $format -eq 4 ];then
tar cvjf $1.tbz2 $1
echo It has been zipped $1 in $1.tbz2
else
echo Incorrect format, restart the script
exit
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment