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