Write a Linux shell script to zip entire folder.

This is a small script which will zip a folder to any zipping algorithms such as zip, gz, bz2 etc.

#!/bin/bash
read -p “please enter the folder location: ” SFOLD1
read -p “Target location to save this zip file: ” DFOLD1
read -p “Select compress type(zip, tar.gz, tar.bz2): ” COMP1
case $COMP1 in
zip)zip ${DFOLD1}/file1.zip $SFOLD1;;
tar.gz) tar cvfz ${DFOLD1}/file1.tar.gz $SFOLD1;;
tar.bz2) tar cvfj ${DFOLD1}/file1.tar.bz2 $SFOLD1;;
*) echo “Please enter a valid compression(zip, tar.gz, tar.bz2)”;exit;;
esac


Let me explain what this script will do. This script will ask for source folder which you want to compress, destination folder where you want to create this compressed folder and the type of compress.

The following two tabs change content below.
Mr Surendra Anne is from Vijayawada, Andhra Pradesh, India. He is a Linux/Open source supporter who believes in Hard work, A down to earth person, Likes to share knowledge with others, Loves dogs, Likes photography. He works as Devops Engineer with Taggle systems, an IOT automatic water metering company, Sydney . You can contact him at surendra (@) linuxnix dot com.