bash - 通过校验和查找目录中修改过的文件
问题描述
我创建了两个文件,一个包含文件夹中所有单个文件的校验和,另一个包含同一文件夹中所有文件经过修改(添加、删除和修改)后的单个校验和。我需要找出在第二次运行 checksum 命令期间被修改的文件。
我试过使用 comm 命令。
comm -23 firstfile secondfile | awk '{print $2}' |sort > added.txt
comm -23 secondfile firstfile | awk '{print $2}' |sort > deleted.txt
我正在尝试找到一种方法可以找到已修改的文件。
解决方案
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
推荐阅读
- c# - C# 自定义文件扩展名过滤器
- c# - ObjectResult 和 HttpResponse 正文
- css - 将自定义字体安装到 WP 中不起作用
- python - 如何在不使用 find 函数的情况下获取字符串中每个字符的位置
- sharepoint - 随机化问题和存储以供以后检索
- python-3.x - pip 在特定的 python 环境中被杀死
- kubernetes - 如何在 kubernetes 中注册现有的 gitlab runner
- java - 仅显示 Firebase 数据库节点中的某些项目
- php - 用于更新 MS SQLSRV 中的记录的 PHP 表单
- python - 如何使用套接字将子进程直接连接到端口?