Created
August 10, 2020 11:27
-
-
Save pd12bbf7608ae1/38267944835269e342c84182f84894d4 to your computer and use it in GitHub Desktop.
计算目标目录内文件的checksum
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# checksum.sh "/path/to/target/dir" | |
dir="$1" | |
cd "$dir" | |
# file=$(ls "$dir") | |
file=$(ls) | |
fileNumber=$(ls | wc -l) | |
for ((i = 1 ; i <= "$fileNumber" ; i++)); do | |
fileName=$(echo "$file" | sed -n "${i}p" ) | |
# if [ -f "${dir}/${fileName}" ]; then | |
if [ -f "${fileName}" ]; then | |
# echo "$fileName" >> "${dir}/checksum.txt" | |
# md5=$(md5sum "${dir}/${fileName}" | cut -d ' ' -f 1) | |
# sha1=$(sha1sum "${dir}/${fileName}" | cut -d ' ' -f 1) | |
# sha256=$(sha256sum "${dir}/${fileName}" | cut -d ' ' -f 1) | |
md5=$(md5sum "${fileName}" | cut -d ' ' -f 1) | |
sha1=$(sha1sum "${fileName}" | cut -d ' ' -f 1) | |
sha256=$(sha256sum "${fileName}" | cut -d ' ' -f 1) | |
# printf "${fileName}\nmd5:\t${md5}\nsha1:\t${sha1}\nsha256:\t${sha256}\n\n" >> "${dir}/checksum.txt" | |
printf "${fileName}\nmd5:\t${md5}\nsha1:\t${sha1}\nsha256:\t${sha256}\n\n" >> "checksum.txt" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment