#!/bin/bash ########################################################### # description: compare many files one time # # author : 骏马金龙 # # blog : # ########################################################### # filename: md5.sh # Usage: $0 file1 file2 file3 ... IFS=$'\n' declare -A md5_array # If use while read loop, the array in while statement will # auto set to null after the loop, so i use for statement # instead the while, and so, i modify the variable IFS to # $'\n'. # md5sum format: MD5 /path/to/file # such as:80748c3a55b726226ad51a4bafa1c4aa /etc/fstab for line in `md5sum "$@"` do index=${line%% *} file=${line##* } md5_array[$index]="$file ${md5_array[$index]}" done # Traverse the md5_array for i in ${!md5_array[@]} do echo -e "the same file with md5: $i\n--------------\n`echo ${md5_array[$i]}|tr ' ' '\n'`\n" done
shell脚本示例:批量比较多个文件的内容是否相同
内容版权声明:除非注明,否则皆为本站原创文章。