linux - 如何记录特定文件的具体修改

标签 linux

我想查看 linux 中一些重要文件(如 nginx.conf)的修改历史。如何记录特定文件的具体修改?修改,例如更改文件的时间和行数。

最佳答案

受@Jonathon 评论的启发,我创建了一个 shell 脚本来监视对特定文件所做的所有更改,同时保留所有更改历史记录。该脚本取决于正在安装的 inotifywait 和 git 包。

你可以在这里找到脚本 https://github.com/hisham-hassan/linux-file-monitor

Usage: file-monitor.sh [-f|--file] <absolute-file-path> [-m|--monitor|-h|--history]  
       file-monitor.sh --help  

 -f,--file <absolute-file-path> Adding a file to the monitored files List. The <absolute-file-path>  
                                is the absolute file path of the file we need to action.  
                                PLEASE NOTE: Relative file path could cause issues in the script,  
                                please make sure to use the abolute path of the file. also try to   
                                avoid sym links, as it has not been tested.  
                                example: file-monitor.sh -f /absolute/path/to/file/test.txt -m  
 -m, --monitor                  Monitoring all the changes on the file. the monitoring will keep  
                                happening as long as the script is running; you may need to run it  
                                in the background.  
                                example: file-monitor.sh -f /absolute/path/to/file/test.txt -m  
 -h, --history                  showing the full history of the file.  
                                To exit, press "q"  
                                example: file-monitor.sh -f /absolute/path/to/file/test.txt -h  
 --uninstall                    uninstalls the script from the bin direcotry,  
                                and removes the monitoring history.  
 --install                      Adds the script to the bin directory, and creates  
                                the directories and files needed for monitoring.  
 --help                         Prints this help message.  

关于linux - 如何记录特定文件的具体修改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47170539/

相关文章:

php - 在我的 linux 服务器上,我收到一个 php 错误,但我看不到错误,为什么?

linux - awk、pipe 和 tail -f 给出意外行为

linux - Bash:将程序输出打印到文件,而不是在屏幕上

linux - 剪贴板 api 是否已从 gtk4 中删除?

sql-server - 如何从sql server获取一个唯一的id

linux - 尝试创建 .ear 文件。但耳朵内部的结构却并不如想象的那样

linux - rsyslog 导入非标准日志

c# - 用 Mono 编译 csharp 项目

python - python 套接字拒绝连接

regex - sed,替换#include 中的反斜杠