1、创建mvnclean.sh脚本,脚本内容如下图,windows系统文件名为mvnclean.bat
#! /bin/bash
read_dir(){
for file in `ls $1` #注意此处这是两个反引号,表示运行系统命令
do
if [ -d $1"/"$file ] #注意此处之间一定要加上空格,否则会报错
then
read_dir $1"/"$file
elif [ -f $1"/pom.xml" ]
then
#echo $1"/"$file #在此处处理文件即可
# if [ $file = "pom.xml" ]
if [ -d $1"/target" ]
then
echo $1
cd $1 && mvn clean
fi
fi
done
}
#读取第一个参数
read_dir $1
#sh mvnclean.sh "/Users/work/apps/"
2、执行命令:#sh mvnclean.sh "待清理的目录"