使用grep反转函数比较两个md5哈希表

时间:2021-08-22 00:11:30

I’ve mounted two .dd images in Linux by using losetup and created a list of hash values for every file located on those images:

我使用losetup在Linux中安装了两个.dd映像,并为这些映像上的每个文件创建了一个散列值列表:

md5deep -r  -e * > winXPimage1.txt
md5deep -r  -e * > winXPimage2.txt

This is how both hash lists look like:

这两个散列列表是这样的:

d41d8cd98f00b204e9800998ecf8427e  /media/74444E0F444DD510/AUTOEXEC.BAT
17d7055859d99a0d606cfaf17ae38638  /media/74444E0F444DD510/boot.ini
d41d8cd98f00b204e9800998ecf8427e  /media/74444E0F444DD510/CONFIG.SYS
88cf0ff92a4a9fa7bd9b7513b2e9e22b  /media/74444E0F444DD510/Documents and Settings/…
 Etc…

The two images contain windows XP installation files and standard programs. The second image, however, also contains a lot of pictures (jpg, png, etc.).

这两个图像包含windows XP安装文件和标准程序。然而,第二张图片也包含了很多图片(jpg、png等)。

I want to use grep to compare the two hash lists that I’ve created and filter out all the hashes related to the .jpg files from the second image.

我希望使用grep来比较我创建的两个散列列表,并过滤掉第二个图像中与.jpg文件相关的所有散列。

I've used the following command to remove all the unnecessary information from the first image:

我使用以下命令从第一张图片中删除所有不必要的信息:

cut -f 1 -d ' ' winXPimage1.txt > winXPimage1New.txt

So now the image1 hash list looks like this:

现在image1散列列表是这样的:

d41d8cd98f00b204e9800998ecf8427e
17d7055859d99a0d606cfaf17ae38638
d41d8cd98f00b204e9800998ecf8427e
etc…

I’m trying to use grep invert command to compare winXPimage1New.txt with winXPimage2.txt (contains jpeg hash values) and display all the non-matching jpg hash lines:

我尝试使用grep反转命令来比较winXPimage1New。txt winXPimage2。txt(包含jpeg散列值),显示所有不匹配的jpg散列:

grep -v -f winXPimage1New.txt winXPimage2.txt/*.jpg
grep -v -f .*[.jpg] winXPimage1New.txt winXPimage2.txt

None of these commands return jpg hash values from the second image hash list. I’m just not sure where exactly do I have to put the .jpg file extension as I’m very new to Linux in general.

这些命令都不会从第二个图像哈希列表返回jpg哈希值。我只是不确定我要把。jpg文件扩展名放在哪里,因为我对Linux很陌生。

1 个解决方案

#1


2  

So you want to filter on .jpg files?

你想要过滤。jpg文件?

Could you start by filtering only .jpg files in your hash lists first, e.g.

你可以先过滤你的哈希表中的.jpg文件吗?

grep -E '\.[jJ][pP][eE]?[gG]$' winXPimage1.txt >only-jpeg1.txt
grep -E '\.[jJ][pP][eE]?[gG]$' winXPimage2.txt >only-jpeg2.txt

Then get your list of md5s on the first system:

然后在第一个系统上获取md5的列表:

cut -f 1 -d ' ' only-jpeg1.txt > only-jpeg1-md5only.txt

Finally attempt your inverted search?

最后尝试反向搜索?

grep -v -f only-jpeg1-md5only.txt only-jpeg2.txt

Update: had to edit because my first two example lines had -v flags which I definitely didn't want. Well spotted by @Alex.

更新:必须编辑,因为我的前两个示例行有-v标志,这是我绝对不想要的。被@Alex发现。

#1


2  

So you want to filter on .jpg files?

你想要过滤。jpg文件?

Could you start by filtering only .jpg files in your hash lists first, e.g.

你可以先过滤你的哈希表中的.jpg文件吗?

grep -E '\.[jJ][pP][eE]?[gG]$' winXPimage1.txt >only-jpeg1.txt
grep -E '\.[jJ][pP][eE]?[gG]$' winXPimage2.txt >only-jpeg2.txt

Then get your list of md5s on the first system:

然后在第一个系统上获取md5的列表:

cut -f 1 -d ' ' only-jpeg1.txt > only-jpeg1-md5only.txt

Finally attempt your inverted search?

最后尝试反向搜索?

grep -v -f only-jpeg1-md5only.txt only-jpeg2.txt

Update: had to edit because my first two example lines had -v flags which I definitely didn't want. Well spotted by @Alex.

更新:必须编辑,因为我的前两个示例行有-v标志,这是我绝对不想要的。被@Alex发现。