linux – 如果目录不具有相同的结构,我如何比较两个目录来比较丢失的文件?

前端之家收集整理的这篇文章主要介绍了linux – 如果目录不具有相同的结构,我如何比较两个目录来比较丢失的文件?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我已经从我们正在使用的组织发送了一个包含新文件和更新文件的硬盘,但我们已经将大部分文件放在我们的服务器上,并希望更新我们的本地版本以匹配他们的文件.

通常情况下,这可能是像rsync这样的工作,但我们的问题是它们提供的目录结构非常糟糕,我们不得不重新安排他们的文件,以便最好地与我们的系统配合使用.

所以,我的问题是:

How can I find out which files in the set they have provided are new
or different to the versions that we have,when the directory
structures are different?

一旦回答了这个问题,我们就可以更新已更改的文件,并找出将新文件放在我们系统上的位置,可能需要手动操作.

解决方法

好的,这是我第一次尝试某事.它看起来适合我所需要的,但我愿意接受更好的建议:

首先,获取我们的文件系统和新数据中所有文件的md5sums:

find /location/of/data -type f -exec md5sum {} ';' > our.md5sums
find /media/newdisk -type f -exec md5sum {} ';' > their.md5sums

我写了一个名为md5diff.py的简短python脚本:

#!/usr/bin/env python
import sys
print "Comparing",sys.argv[1],"to",sys.argv[2]

# Create a dictionary based upon the hashes in source B
dict = {}
for line in open(sys.argv[2]):
    p = line.partition(' ')
    dict[p[0]] = p[2].strip()


# Now go through source A and report where the file is in source B
for line in open(sys.argv[1]):
    p = line.partition(' ')
    if p[0] in dict:
        print line.strip(),"(",sys.argv[2],":",dict[p[0]],")"
    else:
        print line.strip(),"NOT IN",sys.argv[2]

所以现在我可以使用了

./md5diff.py their.md5sums our.md5sums

如果我加入| grep“NOT IN”它只会列出我们尚未拥有的媒体上的文件(或者与我们的文件不同).从他们我可以开始手动攻击已知的差异.

原文链接:https://www.f2er.com/linux/397189.html

猜你在找的Linux相关文章