Linux删除指定目录

#!/bin/sh
cd /root
#递归删除加锁文件
function dels(){

     for tt in `ls $1`
     do 
	  
	  if [[ -d $1"/"$tt ]]; then
	    #echo $tt
            dels $1"/"$tt
	  else
		 # echo "2>"$tt
		  if [[ -e $1"/"$tt ]]; then
		 # echo "-i->"$tt
		   chattr -i $1"/"$tt
		   rm -rf $1"/"$tt
		  fi
		 
	  fi
     done
}



while true; do

	filelist=`ls /root`
	for file in $filelist
	do 
         #排除删除
	 if [[ -f "$file" && $file != "pro.sh" ]]; then
	   chattr -i $file
	   rm -rf $file
	   #rm -rf !(pro.sh)#排除删除
	 fi
	done
        tmp="/tmp"
	dels $tmp
	if [[ -d "$tmp" ]]; then
	  #echo $tmp
	  rm -rf $tmp
	fi
sleep 10
done


猜你喜欢

转载自blog.csdn.net/thl331860203/article/details/72822374