#!/bin/bash
path="/www/wwwroot/www.qianduan.ccc"
function search_file(){
for file in `ls $1`
do
if [ -d $1"/"$file ];then
search_file $1"/"$file
else
if [ "${file##*.}"x != "js"x ] && [ "${file##*.}"x != "html"x ] && [ "${file##*.}"x != "css"x ];then
echo "删除文件$1/$file 成功"
rm -f $1"/"$file
fi
fi
done
}
function del_dir(){
for dir_name in `ls $1`
do
if [ -d $1"/"$dir_name ];then
if [ "$(ls -A $1/$dir_name)" ];then
del_dir $1"/"$dir_name
else
rm -rf $1"/"$dir_name
echo "删除文件夹 $1/$dir_name 成功"
fi
fi
done
}
search_file ${path}
del_dir ${path}
特别注意:执行代码前一定要备份文件!!
空文件夹只能删除最后一层,多层还不知道怎么删,除非执行多次