#!/bin/bash

#Created on 2013-3-12
#@author:victor
#Batch compression all the files in a target directory.

read -p "Pls input directory path:" target_dir
#target_dir=/path            

for file in $(find $target_dir -type f)
do    
     if [ ${file##*.} = gz ]
            then
            echo "${file##*/} ......was tared pass!"
     else
            cd ${file%/*}
            tar zcvf ${file##*/}.tar.gz ${file##*/}
            echo "${file##*/} ......is tared ok!"
            rm -rf ${file##*/}
     fi
done