如题,bash脚本如下:
#!/bin/bash
DIR=$1 # 要打包的目标目录
# 排除的目录列表
if [ "$1" = "retail" ]; then
array=(logs lib target .idea .mvn)
elif [ "$1" = "manager" ]; then
array=(.idea update data/log data/runtime simplewind public/static/ui/lib public/static/js)
#array=(.idea update data/log data/runtime)
else
echo "Usage: sh tar.sh <dir>"
exit
fi
excludes=
for item in ${array[@]}
do
excludes="$excludes --exclude $DIR/$item"
done
# 打包时排除指定目录
tar $excludes -zcf $DIR.tar.gz $DIR
使用时: sh tar.sh targetDir