7zip自带hash校验功能:文件夹、或文件校验

118 篇文章 8 订阅
107 篇文章 0 订阅

7zip自带hash校验功能:文件夹、或文件校验

7zip自带hash校验功能

前言

以前, 为了校验下载后文件的hash, 还专门去找hash工具.

今天查资料, 居然7zip自带了文件hash校验功能, 这多方便啊.

好像只能校验crc32, crc64, sha1, sha256. 能校验的hash类型没有专门的hash工具多, 一般情况下的文件hash校验也够用了.

7z ver : 22.01


实验
7zip版本

。。。。。。省略 。。。。。。。。。。。。。。。。

/// 以下命令:当使用 目录 abc_dir时,将校验每一个文件,以及整个文件夹。

C:\Program Files\7-Zip\7z h -scrcsha1 C:\download\abc_dir > d:\hash.txt

7c1ede0b13dc1901ad97473d8e05fce6a277909e           515  abc\²¶G
---------------------------------------- -------------  ------------
98383eb47394aa19794f4ae54348d4f460f04d9b-000002B6     365096006  

Folders: 272
Files: 1339
Size: 365096006

SHA1   for data:              98383eb47394aa19794f4ae54348d4f460f04d9b-000002B6
SHA1   for data and names:    346920dba4dcf292141a3a0cf82b393f67f50cf5-00000332

Everything is Ok

看看7z.exe具体怎么用

将7z.exe加入环境变量后, 重新打开一个cmd控制台.

进入测试目录, 执行

7z --help

看到以下结果, 这就是7zip命令行的用法.

D:\my_dev\my_tmp\test1>7z --help

7-Zip 21.07 (x64) :

Copyright (c) 1999-2021 Igor Pavlov : 2021-12-26

Usage: 7z <command> [<switches>...] <archive_name> [<file_names>...] [@listfile]

<Commands>
  a : Add files to archive
  b : Benchmark
  d : Delete files from archive

  e : Extract files from archive (without using directory names)
  h : Calculate hash values for files

  i : Show information about supported formats
  l : List contents of archive
  rn : Rename files in archive
  t : Test integrity of archive
  u : Update files to archive

  x : eXtract files with full paths

<Switches>
  -- : Stop switches and @listfile parsing
  -ai[r[-|0]]{@listfile|!wildcard} : Include archives
  -ax[r[-|0]]{@listfile|!wildcard} : eXclude archives
  -ao{a|s|t|u} : set Overwrite mode
  -an : disable archive_name field
  -bb[0-3] : set output log level
  -bd : disable progress indicator
  -bs{o|e|p}{0|1|2} : set output stream for output/error/progress line
  -bt : show execution time statistics
  -i[r[-|0]]{@listfile|!wildcard} : Include filenames
  -m{Parameters} : set compression Method
    -mmt[N] : set number of CPU threads
    -mx[N] : set compression level: -mx1 (fastest) ... -mx9 (ultra)
  -o{Directory} : set Output directory
  -p{Password} : set Password
  -r[-|0] : Recurse subdirectories for name search
  -sa{a|e|s} : set Archive name mode
  -scc{UTF-8|WIN|DOS} : set charset for for console input/output
  -scs{UTF-8|UTF-16LE|UTF-16BE|WIN|DOS|{id}} : set charset for list files

  -scrc[CRC32|CRC64|SHA1|SHA256|*] : set hash function for x, e, h commands

  -sdel : delete files after compression
  -seml[.] : send archive by email
  -sfx[{name}] : Create SFX archive
  -si[{name}] : read data from stdin
  -slp : set Large Pages mode
  -slt : show technical information for l (List) command
  -snh : store hard links as links
  -snl : store symbolic links as links
  -sni : store NT security information
  -sns[-] : store NTFS alternate streams
  -so : write data to stdout
  -spd : disable wildcard matching for file names
  -spe : eliminate duplication of root folder for extract command
  -spf : use fully qualified file paths
  -ssc[-] : set sensitive case mode
  -sse : stop archive creating, if it can't open some input file
  -ssp : do not change Last Access Time of source files while archiving
  -ssw : compress shared files
  -stl : set archive timestamp from the most recently modified file
  -stm{HexMask} : set CPU thread affinity mask (hexadecimal number)
  -stx{Type} : exclude archive type
  -t{Type} : Set type of archive
  -u[-][p#][q#][r#][x#][y#][z#][!newArchiveName] : Update options
  -v{Size}[b|k|m|g] : Create volumes
  -w[{path}] : assign Work directory. Empty path means a temporary directory
  -x[r[-|0]]{@listfile|!wildcard} : eXclude filenames
  -y : assume Yes on all queries

   
  

根据7zip命令行帮助的提示, 我们写个.bat就可以用7zip产生多个文件对应的hash结果文件.

现在测试目录中试试

请添加图片描述

执行命令或写一个bat来测试.

7z h -scrcsha1 fortest7z_1.txt fortest7z_2.txt > hash.txt

执行结果

7-Zip 21.07 (x64) : Copyright (c) 1999-2021 Igor Pavlov : 2021-12-26

Scanning
2 files, 34 bytes (1 KiB)

SHA1                                              Size  Name
---------------------------------------- -------------  ------------
11c972be7e4ceedcaed306c56d29184169656196            22  fortest7z_1.txt
4d88114bd48dd259326fd437089d649abb687124            12  fortest7z_2.txt
---------------------------------------- -------------  ------------
5e51840953dac036e142dbfc75c67cdb24ced2ba-00000000            34  

Files: 2
Size: 34

SHA1   for data:              5e51840953dac036e142dbfc75c67cdb24ced2ba-00000000
SHA1   for data and names:    86bfa0d938ab3a95342bef5cf56808697fdcf5d9-00000000

Everything is Ok

 ------------------------------------------------

7z ver : 22.01

C:\Program Files\7-Zip>7z --help

7-Zip 22.01 (x64) : Copyright (c) 1999-2022 Igor Pavlov : 2022-07-15

Usage: 7z <command> [<switches>...] <archive_name> [<file_names>...] [@listfile]

<Commands>

  a : Add files to archive
  b : Benchmark
  d : Delete files from archive
  e : Extract files from archive (without using directory names)
  h : Calculate hash values for files
  i : Show information about supported formats
  l : List contents of archive
  rn : Rename files in archive
  t : Test integrity of archive
  u : Update files to archive
  x : eXtract files with full paths

<Switches>

  -- : Stop switches and @listfile parsing
  -ai[r[-|0]]{@listfile|!wildcard} : Include archives
  -ax[r[-|0]]{@listfile|!wildcard} : eXclude archives
  -ao{a|s|t|u} : set Overwrite mode
  -an : disable archive_name field
  -bb[0-3] : set output log level
  -bd : disable progress indicator
  -bs{o|e|p}{0|1|2} : set output stream for output/error/progress line
  -bt : show execution time statistics
  -i[r[-|0]]{@listfile|!wildcard} : Include filenames
  -m{Parameters} : set compression Method
    -mmt[N] : set number of CPU threads
    -mx[N] : set compression level: -mx1 (fastest) ... -mx9 (ultra)
  -o{Directory} : set Output directory
  -p{Password} : set Password
  -r[-|0] : Recurse subdirectories for name search
  -sa{a|e|s} : set Archive name mode
  -scc{UTF-8|WIN|DOS} : set charset for for console input/output
  -scs{UTF-8|UTF-16LE|UTF-16BE|WIN|DOS|{id}} : set charset for list files
  -scrc[CRC32|CRC64|SHA1|SHA256|*] : set hash function for x, e, h commands
  -sdel : delete files after compression
  -seml[.] : send archive by email
  -sfx[{name}] : Create SFX archive
  -si[{name}] : read data from stdin
  -slp : set Large Pages mode
  -slt : show technical information for l (List) command
  -snh : store hard links as links
  -snl : store symbolic links as links
  -sni : store NT security information
  -sns[-] : store NTFS alternate streams
  -so : write data to stdout
  -spd : disable wildcard matching for file names
  -spe : eliminate duplication of root folder for extract command
  -spf : use fully qualified file paths
  -ssc[-] : set sensitive case mode
  -sse : stop archive creating, if it can't open some input file
  -ssp : do not change Last Access Time of source files while archiving
  -ssw : compress shared files
  -stl : set archive timestamp from the most recently modified file
  -stm{HexMask} : set CPU thread affinity mask (hexadecimal number)
  -stx{Type} : exclude archive type
  -t{Type} : Set type of archive
  -u[-][p#][q#][r#][x#][y#][z#][!newArchiveName] : Update options
  -v{Size}[b|k|m|g] : Create volumes
  -w[{path}] : assign Work directory. Empty path means a temporary directory
  -x[r[-|0]]{@listfile|!wildcard} : eXclude filenames
  -y : assume Yes on all queries

C:\Program Files\7-Zip>

END
————————————————
版权声明:本文为CSDN博主「LostSpeed」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/LostSpeed/article/details/126175062

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值