检测unix中的目录变化
如何跟踪 UNIX 中特定目录的更改?例如,我启动一些实用程序,该实用程序在执行期间创建一些文件。我想知道在一次特定启动期间创建了哪些确切文件。有什么简单的方法可以获取这些信息吗?问题是:
- 我无法在脚本执行后刷新目录内容
- 使用具有哈希作为复合部分的名称创建的文件。无法从脚本中获取此哈希值以进行后续搜索。
- 可能有多个脚本同时执行,我不想看到同一文件夹中另一个进程创建的文件。
请注意,我不想知道目录是否已按照此处所述<进行更改/a>,我需要理想情况下可以 grep 匹配特定模式的文件名。
How could I track changes of specific directory in UNIX? For example, I launch some utility which create some files during its execution. I want to know what exact files were created during one particular launch. Is there any simple way to get such information? Problem is that:
- I cannot flush directory content after script execution
- Files created with the name that has hash as a compound part. There is no possibility to get this hash from script for subsequent search.
- There could be several scripts executed simultaneously, I do not want to see files created by another process in the same folder.
Please notice that I do not want to know whether directory has been changed as stated here, I need filenames which ideally could be grepped to match specific pattern.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您需要订阅文件系统更改通知。
You need to subscribe to file system change notifications.
您应该使用 FAM、gamin 或 inotify 等工具来检测文件何时被创建、关闭等。
You should use something like FAM, gamin, or inotify to detect when a file has been created, closed, etc.
您可以使用 strace -f myscript 来跟踪脚本发出的所有系统调用,并使用 grep 来过滤创建新文件的系统调用。
You could use
strace -f myscript
to trace all system calls made by the script, and usegrep
to filter the system calls that create new files.您可以使用 Linux 审核系统。这是一个操作方法链接:
http://www.cyberciti.biz/tips/linux-audit-files-to-see-who-made-changes-to-a-file.html
You could use the Linux Auditing System. Here is a howto link:
http://www.cyberciti.biz/tips/linux-audit-files-to-see-who-made-changes-to-a-file.html
您可以使用
script
命令来跟踪启动的命令。You can use the
script
command to track the commands launched.