linux shell递归生成文件MD5文件
shell递归生成文件的MD5文件
#! /bin/bashif [ -n "$1" ]; then DIR_ROOT="$1"else DIR_ROOT=$PWDfiend_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 ]; thenecho $imy_array[$i]=$1"/"$filei=` 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_ROOTdir_md5 $DIR_ROOT
#! /bin/bashif [ -n "$1" ]; then DIR_ROOT="$1"else DIR_ROOT="."fidir_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