bash 检测 unix 中的目录变化

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2370472/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 21:44:21  来源:igfitidea点击:

Detect directory changes in unix

linuxbashunixfilesystems

提问by altern

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:

如何跟踪 UNIX 中特定目录的更改?例如,我启动了一些在执行过程中创建一些文件的实用程序。我想知道在一次特定发布期间创建了哪些确切的文件。有没有简单的方法来获取这些信息?问题在于:

  1. I cannot flush directory content after script execution
  2. 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.
  3. There could be several scripts executed simultaneously, I do not want to see files created by another process in the same folder.
  1. 脚本执行后我无法刷新目录内容
  2. 使用具有哈希作为复合部分的名称创建的文件。无法从脚本中获取此哈希值以进行后续搜索。
  3. 可能有多个脚本同时执行,我不想在同一文件夹中看到另一个进程创建的文件。

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.

请注意,我不想知道目录是否已按照此处所述进行更改,我需要理想情况下可以匹配特定模式的文件名。

回答by Hassan Syed

You need to subscribe to file system change notifications.

您需要订阅文件系统更改通知

回答by Erich Kitzmueller

You could use strace -f myscriptto trace all system calls made by the script, and use grepto filter the system calls that create new files.

您可以使用strace -f myscript跟踪脚本进行的所有系统调用,并用于grep过滤创建新文件的系统调用。

回答by Ignacio Vazquez-Abrams

You should use something like FAM, gamin, or inotify to detect when a file has been created, closed, etc.

您应该使用 FAM、gamin 或 inotify 之类的东西来检测文件何时被创建、关闭等。

回答by a'r

You could use the Linux Auditing System. Here is a howto link:

您可以使用 Linux 审计系统。这是一个操作方法链接:

http://www.cyberciti.biz/tips/linux-audit-files-to-see-who-made-changes-to-a-file.html

http://www.cyberciti.biz/tips/linux-audit-files-to-see-who-made-changes-to-a-file.html

回答by amit

You can use the scriptcommand to track the commands launched.

您可以使用该script命令来跟踪启动的命令。