Skip to main content

This tool only provides Simplified Chinese user interface.

简介

本CLI工具用于计算、存储、验证磁盘文件的hash值,可检查文件是否被篡改。

有以下功能:

  • 将磁盘文件的hash值、大小、路径、登记时间、数据库ID保存到数据库的hash链中
  • 验证数据库中的记录,检查记录的路径、hash值、大小
  • 验证磁盘文件,将hash值、大小、路径与数据库中的记录对比
  • 仅打印数据库中的记录
  • 仅计算磁盘文件的hash值

建议配置环境变量使用。目前大多数下载网站提供sha256值,因此默认使用sha256算法。

CLI命令

路径使用glob语法:* ? [] **

🟢添加文件信息到数据库:

filehash add 'E:\software\python-3.13.12-amd64.exe'
filehash a 'E:\software\*.exe'
filehash a 'E:\software\**\*.exe' # **遍历子目录
filehash a '*.exe' # 当前目录下所有.exe文件
filehash a '*'     # 当前目录下所有文件

🟠验证数据库中的记录:

# 如果磁盘文件已被删除,会提示文件不存在,但不会中止。
filehash verify_record '*\python*.exe'
filehash vr '*\software\*.exe'
filehash vr '*\software\**\*.exe'
filehash vr '*.exe' # 验证数据库中的所有.exe文件
filehash vr '*'     # 验证数据库中的所有记录

🔵验证磁盘上的文件:

# 如果数据库中没有该hash值、大小的数据,程序会报错、中止。
# 此功能可Windows/Linux双系统时使用
filehash verify_file 'E:\software\python-3.13.12-amd64.exe'
filehash vf 'E:\software\*.exe'
filehash vf 'E:\software\**\*.exe'

🟤在终端运行filehash,打印完整的帮助信息:

PS E:\> filehash
usage: filehash [-h] [-m HASH_METH] [-n] [--db-dir DIR] [--backup-dir DIR] [--backup-size SIZE]
                [CMD] [PATH]

文件hash校验。版本: 2.3.15
https://pypi.org/project/fh-tool

positional arguments:
  CMD                   命令
  PATH                  路径,使用glob语法,*表示所有文件,dir/**/*.exe遍历子目录。

options:
  -h, --help            show this help message and exit
  -m, --hash-meth HASH_METH
                        创建数据库时使用的hash算法,覆盖FILEHASH_HASH_METH环境变量。
  -n, --no-space        打印hash时,不添加空格。
  --db-dir DIR          数据库目录,覆盖FILEHASH_DB_DIR环境变量。
  --backup-dir DIR      备份保存的数据库目录,覆盖FILEHASH_BACKUP_DIR环境变量。
  --backup-size SIZE    备份保存的数据库数量,覆盖FILEHASH_BACKUP_SIZE环境变量。

可用命令:
  add/a                      登记文件到数据库
  verify_record/vr           验证数据库中的记录
  print_record/pr            打印数据库中的记录
  print_existing_record/per  打印数据库中尚存在的记录
  verify_file/vf             验证磁盘文件
  print_file/pf              计算文件hash值 (不加载数据库)
  print_accumulated_hash/pah 打印指定ID或所有记录的累积hash

保证存在的hash算法: blake2b, blake2s, md5, sha1, sha224, sha256, sha384,
sha3_224, sha3_256, sha3_384, sha3_512, sha512, shake_128, shake_256
其它可用的hash算法: md5-sha1, ripemd160, sha512_224, sha512_256, sm3
当前创建数据库使用的hash算法: sha256

更新日志

2.3.15: 加载数据库时,验证不递增时间。

2.3.10: 增强hash链验证

2.3.9: print_accumulated_hash命令支持打印所有记录。

2.3.6: 增加print_accumulated_hash命令,打印指定ID的累积hash。

2.3.0: 对数据库记录的glob语法:支持**遍历子目录,运行在Linux/macOS时不再区分大小写、可使用/或\匹配数据库记录的路径分隔符。

2.2.0: 数据库向前不兼容。改变数据库格式,所有元素加入hash链。

Metadata

Release files for fh-tool 2.3.15

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fh-tool 2.3.15
File Size Uploaded Provenance Actions
fh_tool-2.3.15.tar.gz 16.0 kB Without provenance Details for fh_tool-2.3.15.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for fh-tool 2.3.15
File Interpreter ABI Platform Actions
fh_tool-2.3.15-py3-none-any.whl Python 3 none any Details for fh_tool-2.3.15-py3-none-any.whl

Total release size: 30.7 kB

Release files / fh_tool-2.3.15.tar.gz

Download URL fh_tool-2.3.15.tar.gz
Size 16.0 kB
Tags Source
SHA-256 checksum
How to use checksums
d23945d5f695d24dc934a22e5e65cc344a4a61229e66b3df6ef6c91799a24e12
BLAKE2b-256 checksum
How to use checksums
ff465abb94b2f90077850c6aa0a98c665d4c63d79120aeed425c7bce80e4c678
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.14

Release files / fh_tool-2.3.15-py3-none-any.whl

Download URL fh_tool-2.3.15-py3-none-any.whl
Size 14.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6f5e39198897beffba8276146238a55879607984821bcf8924c12ed67c51edf7
BLAKE2b-256 checksum
How to use checksums
686a88f1b4941ce068d4c71f385ee81f8205aca1d3cb0ecf606e150c4bf5d7cd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.14

Security for fh-tool 2.3.15

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page