如何计算目录的md5校验和? [英] How can I calculate an md5 checksum of a directory?

查看:305
本文介绍了如何计算目录的md5校验和?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为放置在目录和所有子目录下的所有特定类型的文件(例如*.py)计算一个md5校验摘要.

I need to calculate a summary md5 checksum for all files of a particular type (*.py for example) placed under a directory and all sub-directories.

做到这一点的最佳方法是什么?

What is the best way to do that?

提出的解决方案非常好,但这并不是我真正需要的.我正在寻找一种获取单个摘要校验和的解决方案,该校验和将唯一标识整个目录-包括其所有子目录的内容.

The proposed solutions are very nice, but this is not exactly what I need. I'm looking for a solution to get a single summary checksum which will uniquely identify the directory as a whole - including content of all its sub-directories.

推荐答案

find /path/to/dir/ -type f -name "*.py" -exec md5sum {} + | awk '{print $1}' | sort | md5sum

find命令列出所有以.py结尾的文件. 为每个.py文件计算md5sum. awk用于挑选md5sums(忽略文件名,文件名可能不是唯一的). md5sums被排序. 然后返回此排序列表的md5sum.

The find command lists all the files that end in .py. The md5sum is computed for each .py file. awk is used to pick off the md5sums (ignoring the filenames, which may not be unique). The md5sums are sorted. The md5sum of this sorted list is then returned.

我已经通过复制测试目录对此进行了测试:

I've tested this by copying a test directory:

rsync -a ~/pybin/ ~/pybin2/

我重命名了〜/pybin2中的某些文件.

I renamed some of the files in ~/pybin2.

find...md5sum命令为两个目录返回相同的输出.

The find...md5sum command returns the same output for both directories.

2bcf49a4d19ef9abd284311108d626f1  -

这篇关于如何计算目录的md5校验和?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆