日期:2014-05-16 浏览次数:20655 次
#! /bin/bash if [ -n "$1" ]; then DIR_ROOT="$1" else DIR_ROOT=$PWD fi end_with(){ echo $1 | grep $2 >/dev/null 2>&1 if [ $? -eq 0 ];then return 1 fi return 0 } dir_md5(){ if [ "$(ls -A $1)" ]; then declare -i i=0 declare -a my_array for file in ` ls $1 ` do if [ -d $1"/"$file ]; then echo $i my_array[$i]=$1"/"$file i=` expr $i + 1 ` else if end_with "$file" "md5\.sh$"; then if end_with "$file" "md5_d\.sh$"; then cd $1"/" md5sum $file > $file.md5 fi fi fi done for my_dir in ${my_array[*]} do dir_md5 $my_dir cd $1"/" done fi } sh +x md5_d.sh $DIR_ROOT dir_md5 $DIR_ROOT
#! /bin/bash if [ -n "$1" ]; then DIR_ROOT="$1" else DIR_ROOT="." fi dir_md5(){ for file in $1/* do if [ -d $file ]; then dir_md5 $file else #左边最长匹配模式 if [ ${file##*.} = "md5" ]; then rm -f $file fi fi done } dir_md5 $DIR_ROOT