最後更新: 2019-01-02
介紹
它的功能是校對/計算檔案完整性 (128 bit MD5 值)
目錄
md5sum
Syntax
md5sum [OPTION] [FILE]...
例子
1. 查看某檔案的 md5 值
md5sum filename.txt
ab65da9ee3e50f6fdc04435cf29b65fd filename.txt
2. 為一個目錄下的所以檔案建立 checksum 檔
md5sum Folder/* > folder.md5.txt
MD5 Folder/Filename
Notes: 由於目的地的目錄結構可能不一樣, 建議使用
cd FolderA; md5sum * > ../folder.md5.txt
在目的地可以
cd FolderB; md5sum -c ../file.md5.txt
3. 效對 checksum 檔內指定的檔案的正確性
md5sum -c squirrelmail-webmail-1.4.22.tar.gz.md5
squirrelmail-webmail-1.4.22.tar.gz: OK
當檔案被人修改過就會有如下結果
cartoon_list.txt: FAILED md5sum: WARNING: 1 of 1 computed checksum did NOT match
4. 計算及校對一整個目錄
# 計算
cd /home/vhosts/datahunter.org
rm hash.txt
find web -type f -exec md5sum {} \; >> hash.txt
chmod 600 hash.txt
# 校對
md5sum -c hash.txt
其他
"0" 's md5sum
# -b, --binary read in binary mode
# the two modes(text, binary) always produce same result
# outputting a ‘*’ flag
dd if=/dev/zero bs=10M count=10 2>/dev/null | md5sum -b
2f282b84e7e608d5852449ed940bfc51 *-
P.S.
- 100M 's "0" 2f282b84e7e608d5852449ed940bfc51
- 1GB 's "0" e5c834fbdaa6bfd8eac5eb9404eefdd4
- 1GiB 's "0" cd573cfaace07e7949bc0c46028904ff
sha256sum
sha256sum --ignore-missing -c SHA256SUMS
cksum
Print CRC checksum and byte counts of each FILE
cksum [FILE]
ie.
cksum rd.gz
3095222862 6292398 rd.gz