Pages

Tuesday, August 14, 2012

Linux/Unix Bash shell script to zip entire folder

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.

0 comments:

Post a Comment