我有多个电报数据导出,我想计算所有文件的 md5 和 sha256 哈希值,但它只计算根目录中的文件
$ md5sum `ls` > hash.md5
md5sum: chats: Is a directory
md5sum: css: Is a directory
md5sum: images: Is a directory
md5sum: js: Is a directory
md5sum: lists: Is a directory
md5sum: profile_pictures: Is a directory
这在输出文件中
7e315ce28aa2f6474e69a7b7da2b5886 export_results.html
66281ec07a2c942f50938f93b47ad404 hash.md5
da5e2fde21c3e7bbbdb08a4686c3d936 ID.txt
有办法得到这样的东西吗?
5750125fe13943f6b265505b25828400 js/script.js
对不起我的英语
使用 bash:
shopt -s globstar
md5sum ** >/tmp/hash.md5
忽略此类错误:
md5sum: foobar: Is a directory
来自
man bash
:
:如果设置,路径名扩展上下文中使用的模式 ** 将匹配所有文件以及零个或多个目录和子目录。如果模式后跟 /,则仅目录和子目录匹配。globstar
hashdeep
是一个有帮助的工具,但默认情况下可能不会安装。
hashdeep
直接执行并具有更多优点,例如二进制文件也适用于 Windows。
您的问题将通过以下命令使用
hashdeep
得到回答:
hashdeep -c md5,sha256 -r -o f -l . > hash.md5
这可以通过一个命令计算所有子目录中所有文件的 md5 和 sha256。
由于文件的缓存效果,同时创建 md5 和 sha256 可能会更快。此外,该命令还可以选择使用多线程,这可以使用多核 CPU 和快速磁盘来加快任务速度。
或者,您可以将
find
与 -exec
选项一起使用:
find topdir -type f -exec md5sum {} + > MD5SUMS
将
topdir
替换为实际目录名称,或者如果您想处理当前目录(及其子目录,如果有),则将其删除。这只会计算常规文件的校验和(因此,不会出现“md5sum:某物:是一个目录”错误),并且不会遇到“参数列表太长”问题。
您可以使用以下方法来完成任务。
find . -type f -exec md5sum {} + >> log_checksum.txt
#. (dot) can be replaced with the location you need to run the command
#curly braces {} to mention, filenames of the command output will be passed to the md5sum command as arguments
#(+) plus sign is added to make sure files are passed as arguments to a single md5sum command, to prevent running a separate md5sum process for each file
在 zsh 上使用以下命令:
md5sum */**(.) > md5sum.txt
并测试文件类型
md5sum -c md5sum.txt