File Hasher
Compute, verify, and compare file hashes. Supports all hashlib algorithms. Zero dependencies.
Quick Start
CODEBLOCK0
Commands
hash
Compute file hash with one or more algorithms:
CODEBLOCK1
verify
Check a file against an expected hash:
CODEBLOCK2
Exit code 0 = match, 1 = mismatch.
check
Verify files from a checksum file (sha256sum/md5sum/BSD format):
CODEBLOCK3
Auto-detects algorithm from hash length and BSD format headers.
compare
Compare two files by hash:
CODEBLOCK4
directory
Hash all files in a directory:
CODEBLOCK5
string
Hash a text string directly:
CODEBLOCK6
algorithms
List all available hash algorithms:
CODEBLOCK7
文件哈希工具
计算、验证和比较文件哈希值。支持所有hashlib算法。零依赖。
快速开始
bash
计算文件哈希值(SHA-256)
python3 scripts/file_hasher.py hash myfile.txt
验证下载文件
python3 scripts/file_hasher.py verify image.iso -e abc123def456...
比较两个文件
python3 scripts/file_hasher.py compare file1.txt file2.txt
命令
hash
使用一个或多个算法计算文件哈希值:
bash
python3 scripts/file_hasher.py hash file.txt # SHA-256
python3 scripts/file_hasher.py hash file.txt -a md5 # MD5
python3 scripts/file_hasher.py hash file.txt -a md5,sha1,sha256 # 多种算法
python3 scripts/file_hasher.py hash *.py --bsd # BSD格式
python3 scripts/file_hasher.py hash data.bin --json # JSON输出
verify
检查文件是否与预期哈希值匹配:
bash
python3 scripts/file
hasher.py verify image.iso -e hash>
python3 scripts/file_hasher.py verify file.tar.gz -e -a sha512
退出码0表示匹配,1表示不匹配。
check
从校验和文件(sha256sum/md5sum/BSD格式)验证文件:
bash
python3 scripts/file_hasher.py check SHA256SUMS
python3 scripts/file_hasher.py check checksums.txt -a md5
自动根据哈希长度和BSD格式头检测算法。
compare
通过哈希值比较两个文件:
bash
python3 scripts/file_hasher.py compare original.bin copy.bin
python3 scripts/file_hasher.py compare a.txt b.txt -a md5
directory
计算目录中所有文件的哈希值:
bash
python3 scripts/file_hasher.py directory ./src # 顶层目录
python3 scripts/file_hasher.py directory ./project -r # 递归遍历
python3 scripts/file_hasher.py directory ./dist -r --bsd -a md5 # BSD格式 + MD5
string
直接计算文本字符串的哈希值:
bash
python3 scripts/file_hasher.py string hello world
python3 scripts/file_hasher.py string password -a md5,sha256,sha512
algorithms
列出所有可用的哈希算法:
bash
python3 scripts/file_hasher.py algorithms