查找两个文件夹之间的公用文件 [英] Find common files between two folders
本文介绍了查找两个文件夹之间的公用文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给出两个根文件夹A和B,
Given two root folders A and B,
如何在A和B的子文件夹之间找到重复的文本文件?
how can I find duplicate text files between subfolders of A and of B ?
换句话说,我正在考虑A和B中文件的交集.
In other words, I am considering the intersection of files from A and B.
我不想在A或B中找到重复的文件,而只希望在A和B中找到文件.
I dont want to find duplicate files within A, or within B, but only files, that are in A and in B.
修改
重复是指文件内容相同
推荐答案
如注释部分所述,我将为每个文件生成一个MD5校验和,仅生成一次-然后查找重复的校验和.
As indicated in the comments section, I would generate a single MD5 checksum for each file, just once - then look for duplicated checksums.
类似这样的东西:
find DirA -name \*.txt -exec md5sum {} + > /tmp/a
find DirB -name \*.txt -exec md5sum {} + > /tmp/b
现在找到两个文件中都出现的所有校验和.
Now find all those checksums that occur in both files.
因此,遵循以下原则:
awk 'FNR==NR{md5[$1];next}$1 in md5' /tmp/[ab]
或者也许像这样:
awk 'FNR==NR{s=$1;md5[s];$1="";name[s]=$0;next}$1 in md5{s=$1;$1="";print name[s] " : " $0}' /tmp/[ab]
这篇关于查找两个文件夹之间的公用文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文