相关疑难解决方法(0)

使用 md5sum 比较 2 个文件的内容

如何在一个命令中比较 2 个文件的 md5 和?

我可以分别计算它们:

my_prompt$ md5sum file_1.sql
20f750ff1aa835965ec93bf36fd8cf22  file_1.sql

my_prompt$ md5sum file_2.sql
733d53913c366ee87b6ce677971be17e  file_2.sql
Run Code Online (Sandbox Code Playgroud)

但想知道如何将其合并到单个比较计算中。我尝试过不同的方法但都失败了:

my_prompt$ md5sum file_1.sql == md5sum file_2.sql
my_prompt$ `md5sum file_1.sql` == `md5sum file_2.sql`
my_prompt$ (md5sum file_1.sql) == (md5sum file_2.sql)
my_prompt$ `md5sum file_1.sql` -eq `md5sum file_2.sql`
Run Code Online (Sandbox Code Playgroud)

我在这里缺少什么?尝试了以下Compare md5 sums in bash scripthttps://unix.stackexchange.com/questions/78338/a-simpler-way-of-comparing-md5-checksum,但没有运气。

bash ubuntu md5 md5sum windows-subsystem-for-linux

8
推荐指数
2
解决办法
2万
查看次数

Bash循环来比较文件

我显然遗漏了一些东西,并且知道问题是它创建了一个空白输出,这就是为什么它无法比较.然而,如果有人能够对此有所了解,那就太棒了 - 我没有把它隔离开来.

最后,我试图将md5sum存储在txt文件中的列表与存储在服务器上的列表进行比较.如果有错误,我需要它报告.这是输出:

root@vps [~/testinggrounds]# cat md5.txt | while read a b; do
>   md5sum "$b" | read c d
>   if [ "$a" != "$c" ] ; then
>     echo "md5 of file $b does not match"
>   fi
> done
md5 of file file1 does not match
md5 of file file2 does not match

root@vps [~/testinggrounds]# md5sum file*
2a53da1a6fbfc0bafdd96b0a2ea29515  file1
bcb35cddc47f3df844ff26e9e2167c96  file2

root@vps [~/testinggrounds]# cat md5.txt
2a53da1a6fbfc0bafdd96b0a2ea29515  file1
bcb35cddc47f3df844ff26e9e2167c96  file2
Run Code Online (Sandbox Code Playgroud)

linux bash loops if-statement while-loop

4
推荐指数
1
解决办法
9192
查看次数