Skip to content

Instantly share code, notes, and snippets.

@wanghongfei
Created April 2, 2016 13:15
Show Gist options
  • Select an option

  • Save wanghongfei/1e79e0ab1629de64ce80b079c44daec9 to your computer and use it in GitHub Desktop.

Select an option

Save wanghongfei/1e79e0ab1629de64ce80b079c44daec9 to your computer and use it in GitHub Desktop.
递归当前目录下所有target/目录
#!/bin/bash
log_info() {
echo "[INFO] => $1"
}
log_del() {
echo "[DELETE] => $1"
}
total=0
clear_dir() {
base_path=`pwd`
#log_info "Entering ${base_path}"
# 遍历当前目录下所有文件
for filename in `ls`
do
# 判断是否是目录
if [ -d ${filename} ]; then
# 判断是否是target目录
if [ ${filename} == "target" ]; then
rm -rf ${filename}
log_del "${base_path}/${filename}"
total=$[total + 1]
continue
fi
# 不是目录
cd ${filename}
clear_dir
fi
done
cd ..
}
# 删除dir_path目录中的target/目录
clear_dir
echo "found ${total} directories"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment