#!/bin/bash
if [ -z $1 ]; then
echo "please input directory"
exit 2
fi
if [ -d $1 ]; then
cd $1
else
echo "Then directory error!"
exit 1
fi
for i in `ls`
do
tar cfz $i.gz $i
done
运行脚本,需要指定一个目录作为参数。脚本将会对该目录下所有文件单独打包。