用git bash调用md5sum进行批量MD5计算

对于非常大的文件或者很重要的文件,在不稳定的网络环境下,可能文件的某些字节会损坏。此时,对文件计算MD5即可以校验其完整性。比如本次的 OpenStreetMap 导出包,我的学弟反馈通过网盘下载无法解压,并建议我增加每个文件的MD5校验。

对于文件非常多的情况,需要批量计算。最简便的方法是使用git自带的md5sum进行计算。

1. 安装git并进入bash

到 https://git-scm.com/ 下载git,并安装。

安装后,右键单击网盘下载的文件夹,选择“git bash” 进入bash:

bash
bash
可以查看 md5sum的说明

$ md5sum --help
Usage: md5sum [OPTION]... [FILE]...
Print or check MD5 (128-bit) checksums.

With no FILE, or when FILE is -, read standard input.

  -b, --binary         read in binary mode (default unless reading tty stdin)
  -c, --check          read MD5 sums from the FILEs and check them
      --tag            create a BSD-style checksum
  -t, --text           read in text mode (default if reading tty stdin)
  -z, --zero           end each output line with NUL, not newline,
                       and disable file name escaping

The following five options are useful only when verifying checksums:
      --ignore-missing  don't fail or report status for missing files
      --quiet          don't print OK for each successfully verified file
      --status         don't output anything, status code shows success
      --strict         exit non-zero for improperly formatted checksum lines
  -w, --warn           warn about improperly formatted checksum lines

      --help     display this help and exit
      --version  output version information and exit

The sums are computed as described in RFC 1321.  When checking, the input
should be a former output of this program.  The default mode is to print a
line with checksum, a space, a character indicating input mode ('*' for binary,
' ' for text or where binary is insignificant), and name for each FILE.

Note: There is no difference between binary mode and text mode on GNU systems.

GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
Report any translation bugs to <https://translationproject.org/team/>
Full documentation <https://www.gnu.org/software/coreutils/md5sum>
or available locally via: info '(coreutils) md5sum invocation'

2. 批量计算md5

Linux常见命令 find 能够枚举文件并批量执行指令。

执行下面的指令,可以在屏幕输出各个文件的md5:

$ find ./Arch*.* -exec md5sum {} \;
d060dd81785d957ae4e2bbd4f9ebeb4e *./ArchOSManjaro.7z.001
b7326e73452d3fbbc56a889f55aa9a14 *./ArchOSManjaro.7z.002
805c9ef68887953554c6c160c2a72eeb *./ArchOSManjaro.7z.003
#...
2cc5ab567abba1d7e3a284ec5c383d84 *./ArchOSManjaro.7z.059
$

执行下面的指令,可以在文件输出各个文件的md5:

$ find ./Arch*.* -exec md5sum {} >> md5.txt \;

3.比较两个文件是否一致

我们假设本地校验结果放在check.txt,标准校验结果放在 md5.txt,则使用下面指令比较:

$ diff --help
Usage: diff [OPTION]... FILES
Compare FILES line by line.

Mandatory arguments to long options are mandatory for short options too.
      --normal                  output a normal diff (the default)
  -q, --brief                   report only when files differ
  -s, --report-identical-files  report when two files are the same
  -c, -C NUM, --context[=NUM]   output NUM (default 3) lines of copied context
  -u, -U NUM, --unified[=NUM]   output NUM (default 3) lines of unified context
  -e, --ed                      output an ed script
  -n, --rcs                     output an RCS format diff
  -y, --side-by-side            output in two columns
  -W, --width=NUM               output at most NUM (default 130) print columns
      --left-column             output only the left column of common lines
      --suppress-common-lines   do not output common lines

  -p, --show-c-function         show which C function each change is in
  -F, --show-function-line=RE   show the most recent line matching RE
      --label LABEL             use LABEL instead of file name and timestamp
                                  (can be repeated)

  -t, --expand-tabs             expand tabs to spaces in output
  -T, --initial-tab             make tabs line up by prepending a tab
      --tabsize=NUM             tab stops every NUM (default 8) print columns
      --suppress-blank-empty    suppress space or tab before empty output lines
  -l, --paginate                pass output through 'pr' to paginate it

  -r, --recursive                 recursively compare any subdirectories found
      --no-dereference            don't follow symbolic links
  -N, --new-file                  treat absent files as empty
      --unidirectional-new-file   treat absent first files as empty
      --ignore-file-name-case     ignore case when comparing file names
      --no-ignore-file-name-case  consider case when comparing file names
  -x, --exclude=PAT               exclude files that match PAT
  -X, --exclude-from=FILE         exclude files that match any pattern in FILE
  -S, --starting-file=FILE        start with FILE when comparing directories
      --from-file=FILE1           compare FILE1 to all operands;
                                    FILE1 can be a directory
      --to-file=FILE2             compare all operands to FILE2;
                                    FILE2 can be a directory

  -i, --ignore-case               ignore case differences in file contents
  -E, --ignore-tab-expansion      ignore changes due to tab expansion
  -Z, --ignore-trailing-space     ignore white space at line end
  -b, --ignore-space-change       ignore changes in the amount of white space
  -w, --ignore-all-space          ignore all white space
  -B, --ignore-blank-lines        ignore changes where lines are all blank
  -I, --ignore-matching-lines=RE  ignore changes where all lines match RE

  -a, --text                      treat all files as text
      --strip-trailing-cr         strip trailing carriage return on input
      --binary                    read and write data in binary mode

  -D, --ifdef=NAME                output merged file with '#ifdef NAME' diffs
      --GTYPE-group-format=GFMT   format GTYPE input groups with GFMT
      --line-format=LFMT          format all input lines with LFMT
      --LTYPE-line-format=LFMT    format LTYPE input lines with LFMT
    These format options provide fine-grained control over the output
      of diff, generalizing -D/--ifdef.
    LTYPE is 'old', 'new', or 'unchanged'.  GTYPE is LTYPE or 'changed'.
    GFMT (only) may contain:
      %<  lines from FILE1
      %>  lines from FILE2
      %=  lines common to FILE1 and FILE2
      %[-][WIDTH][.[PREC]]{doxX}LETTER  printf-style spec for LETTER
        LETTERs are as follows for new group, lower case for old group:
          F  first line number
          L  last line number
          N  number of lines = L-F+1
          E  F-1
          M  L+1
      %(A=B?T:E)  if A equals B then T else E
    LFMT (only) may contain:
      %L  contents of line
      %l  contents of line, excluding any trailing newline
      %[-][WIDTH][.[PREC]]{doxX}n  printf-style spec for input line number
    Both GFMT and LFMT may contain:
      %%  %
      %c'C'  the single character C
      %c'\OOO'  the character with octal code OOO
      C    the character C (other characters represent themselves)

  -d, --minimal            try hard to find a smaller set of changes
      --horizon-lines=NUM  keep NUM lines of the common prefix and suffix
      --speed-large-files  assume large files and many scattered small changes
      --color[=WHEN]       color output; WHEN is 'never', 'always', or 'auto';
                             plain --color means --color='auto'
      --palette=PALETTE    the colors to use when --color is active; PALETTE is
                             a colon-separated list of terminfo capabilities

      --help               display this help and exit
  -v, --version            output version information and exit

FILES are 'FILE1 FILE2' or 'DIR1 DIR2' or 'DIR FILE' or 'FILE DIR'.
If --from-file or --to-file is given, there are no restrictions on FILE(s).
If a FILE is '-', read standard input.
Exit status is 0 if inputs are the same, 1 if different, 2 if trouble.

Report bugs to: bug-diffutils@gnu.org
GNU diffutils home page: <https://www.gnu.org/software/diffutils/>
General help using GNU software: <https://www.gnu.org/gethelp/>

执行指令:

$ diff  check.txt  md5.txt
36c36
< 23dfa036cd5d772f01173da67ebf2634 *./ArchOSManjaro.7z.029
---
> db2ce0bc5c39fd5d8f672f478788095c *./ArchOSManjaro.7z.029

可以看到第29号文件有问题。

使用 -y 选项,可以查看完整输出(左右两列)

$ diff -y check.txt  md5.txt
..
e155774f7dd158ded02d9a9aae68f5eb *./ArchOSManjaro.7z.028        e155774f7dd158ded02d9a9aae68f5eb *./ArchOSManjaro.7z.028
23dfa036cd5d772f01173da67ebf2634 *./ArchOSManjaro.7z.029      | db2ce0bc5c39fd5d8f672f478788095c *./ArchOSManjaro.7z.029
c8c32363ebd14a7eefce1cadaaa64def *./ArchOSManjaro.7z.030        c8c32363ebd14a7eefce1cadaaa64def *./ArchOSManjaro.7z.030
...

不一致的行,会用竖线“|”标记。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/335068.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

web学习笔记(十六)

目录 HTML5新增标记汇总 1.新增语义化标签 2.新增音频和视频标签 2.1音频标签 audio 2.1视频标签 video 3.新增图像标签 4.新增表单元素和表单控件 5.新增应用程序标签&#xff08;使用率较低&#xff09; HTML5新增标记汇总 1.新增语义化标签 新增语义化标签能够便于…

BossCMS RCE

简介 BossCMS是一款基于自主研发PHP框架MySQL架构的内容管理系统&#xff0c;能够满足各类网站开发建设的需求。系统开源、安全、稳定、简洁、易开发、专注为中小型企业及政企单位、个人站长、广大开发者、建站公司提供一套简单好用的网站内容管理系统解决方案。官网提供了大量…

Linux 可观测性 BPFeBPF 以及 BCCbpftrace 认知

写在前面 博文内容为 《BPF Performance Tools》 读书笔记整理&#xff0c;对原书内容做了摘要博文内容涉及&#xff1a; BPF 和 eBPF 认知BCC 和 bpftrace 认知BCC 和 bpftrace 工具简单认知 理解不足小伙伴帮忙指正 对每个人而言&#xff0c;真正的职责只有一个&#xff1a;找…

PTA 6-11 先序输出叶结点

本题要求按照先序遍历的顺序输出给定二叉树的叶结点。 函数接口定义&#xff1a; void PreorderPrintLeaves( BinTree BT ); 其中BinTree结构定义如下&#xff1a; typedef struct TNode *Position; typedef Position BinTree; struct TNode{ElementType Data;BinTree Left…

C++ | 五、哈希表 Hash Table(数组、集合、映射)

哈希表基础 哈希表是一种数据结构&#xff08;哈希表包含数组&#xff0c;和前两篇文章叙述的字符串、链表平级&#xff09;哈希表概念&#xff1a;类似于Python里的字典类型&#xff0c;哈希表把关键码key值通过哈希函数来和哈希表上的索引对应起来&#xff0c;之后输入key值…

操作系统——进程管理篇

操作系统——进程管理篇&#xff08;王道23年版&#xff09; 2.1_1_进程的概念、组成、特征 1.进程的概念 程序&#xff1a;是静态的&#xff0c;就是个存放在磁盘里的可执行文件&#xff0c;就是一系列的指令集合 进程&#xff1a;是动态的&#xff0c;是程序的一次执行过…

x-cmd pkg | aliyun - 阿里云 CLI

目录 简介首次用户技术特点竞品和相关作品进一步阅读 简介 aliyun 是基于阿里云 OpenAPI 的管理工具&#xff0c;用于与阿里云服务交互&#xff0c;管理阿里云资源。 首次用户 使用 x env use aliyun 即可自动下载并使用 在终端运行 eval "$(curl https://get.x-cmd.com…

Red Hat Enterprise Linux 9.3 安装图解

引导和开始安装 选择倒计时结束前&#xff0c;通过键盘上下键选择下图框选项&#xff0c;启动图形化安装过程。需要注意的不同主板默认或者自行配置的固件类型不一致&#xff0c;引导界面有所不同。也就是说使用UEFI和BIOS的安装引导界面是不同的&#xff0c;如图所示。若手动调…

MySQL缓冲池(Buffer Pool)深入解析:原理、组成及其在数据操作中的核心作用

在关系型数据库管理系统&#xff08;RDBMS&#xff09;中&#xff0c;性能优化一直是数据库管理员和开发者关注的焦点。作为最流行的开源RDBMS之一&#xff0c;MySQL提供了多种优化手段&#xff0c;其中InnoDB存储引擎的缓冲池&#xff08;Buffer Pool&#xff09;是最为关键的…

二、Flask学习之CSS

1.CSS在HTML中的三种表示方法 1.1 直接在标签中添加 <div><span style"color: orange">欢迎光临</span> </div>1.2 在头部添加 <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"&g…

2024年MacBookPro电脑数据恢复软件EasyRecovery数据恢复

前天新入手了一台MacBook pro&#xff0c;第一次用Mac激动的心情简直难以言喻&#xff0c;可是随后这激动的心情顿时就烟消云散了&#xff0c;因为对Mac操作系统的不熟练&#xff0c;导致我删除了一份很重要的Word文件。MacBook pro如何恢复误删除的文件?就这件事我向朋友求助…

SpringMVC下半篇之整合ssm

4.ssm整合 4.1.创建表 CREATE TABLE account (id int(11) NOT NULL AUTO_INCREMENT,name varchar(20) DEFAULT NULL,money double DEFAULT NULL,PRIMARY KEY (id) ) ENGINEInnoDB DEFAULT CHARSETutf8;4.2.创建工程 4.3.pom.xml <?xml version"1.0" encoding&…

第十一站:运算符重载operate(+-*/)

目录 使用成员函数重载运算符 使用非成员函数重载运算符 使用重载函数运算整数 禁区: 赋值重载运算符 bug: 关系重载运算符>< 下标运算符重载 bug 输入输出运算符重载<<,>> 使用成员函数 使用友元函数 (更方便) 普通类型>类类型 类类型>普通类型…

OpenCV-Python(48):K均值聚类

目标 学习K值聚类的概念以及工作原理。K均值聚类的OpenCV实现 背景 下面用一个最常用的例子来给大家介绍K 值聚类。 话说有一个公司要生产一批新的T 恤。很明显他们要生产不同大小的T 恤来满足不同客客的要求。所以这个公司搜集了很多人的身高和体重信息&#xff0c;并把这些…

【C语言】编译和链接深度剖析

文章目录 &#x1f4dd;前言&#x1f320; 翻译环境和运行环境&#x1f309;翻译环境 &#x1f320;预处理&#xff08;预编译&#xff09;&#x1f309;编译 &#x1f320;词法分析&#x1f320;语法分析 &#x1f309;语义分析&#x1f320;汇编 &#x1f309; 链接&#x1f…

23号资源——电力系统程序集合已提供下载资源

23号资源&#xff1a;程序集合包含9个程序&#xff08;经典电力系统经济调度程序&#xff1b;2解决带储&#xff1b;3智能微电网PSO优化算法&#xff1b;微电网调度等等&#xff0c;见资源描述&#xff09;资源-CSDN文库https://download.csdn.net/download/LIANG674027206/887…

C++继承(万字详!!)

文章目录 继承的概念及定义继承的概念继承定义 基类和派生类对象赋值转换继承中的作用域派生类的默认成员函数继承与友元继承与静态成员复杂的菱形继承及菱形虚拟继承菱形继承菱形虚拟继承 继承的总结和反思笔试面试题 继承的概念及定义 继承的概念 继承(inheritance) 机制是面…

【Docker】实战多阶段构建 Laravel 镜像

作者主页&#xff1a; 正函数的个人主页 文章收录专栏&#xff1a; Docker 欢迎大家点赞 &#x1f44d; 收藏 ⭐ 加关注哦&#xff01; 本节适用于 PHP 开发者阅读。Laravel 基于 8.x 版本&#xff0c;各个版本的文件结构可能会有差异&#xff0c;请根据实际自行修改。 准备 新…

开源模型应用落地-qwen模型小试-入门篇(五)

一、前言 这是关于qwen模型入门的最后一篇文章。主要介绍如何使用魔搭的API在本地调用qwen模型。此外&#xff0c;通过阅读这一系列的文章&#xff0c;如果您真的亲自动手实践过&#xff0c;我相信您已经掌握了qwen模型的基本使用方法。 二、术语 2.1. ModelScope社区 打造下一…

HCIA—— 16每日一讲:HTTP和HTTPS、无状态和cookie、持久连接和管线化、(初稿丢了,这是新稿,请宽恕我)

学习目标&#xff1a; HTTP和HTTPS、无状态和cookie、持久连接和管线化、HTTP的报文、URI和URL&#xff08;初稿丢了&#xff0c;这是新稿&#xff0c;请宽恕我&#x1f636;‍&#x1f32b;️&#xff09; 学习内容&#xff1a; HTTP无状态和cookieHTTPS持久连接和管线化 目…
最新文章