首页 > 解决方案 > 通过校验和查找目录中修改过的文件

问题描述

我创建了两个文件,一个包含文件夹中所有单个文件的校验和,另一个包含同一文件夹中所有文件经过修改(添加、删除和修改)后的单个校验和。我需要找出在第二次运行 checksum 命令期间被修改的文件。

我试过使用 comm 命令。

comm -23 firstfile secondfile | awk '{print $2}' |sort > added.txt
comm -23 secondfile firstfile | awk '{print $2}' |sort > deleted.txt

我正在尝试找到一种方法可以找到已修改的文件。

标签: bashlast-modifieddata-integrity

解决方案


md5sum *.txt > sum1

md5sum *.txt > sum2

diff sum1 sum2

校验和不是监视更改的好方法,因为它们仅限于校验和差异。

如果你想对文件系统事件采取行动,你可以使用inotify ( http://man7.org/linux/man-pages/man7/inotify.7.html )

如果您只想观看事件,您可以使用iwatch ( http://iwatch.sourceforge.net/documentation.html ) 来检测目录中的更改。替代方法是由 fakebook ( https://www.tecmint.com/watchman-monitor-file-changes-in-linux/ )开发的 watchman


推荐阅读