加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

如何在Linux中更改目录内容时自动运行脚本?

发布时间:2020-12-13 18:44:45 所属栏目:Linux 来源:网络整理
导读:我想在新文件复制到特定目录时自动运行脚本.换句话说,Linux中是否有一种方法可以“监视”目录以进行更改,然后运行某些内容以响应更改? 解决方法 如果你很幸运能够使用基于debian的发行版,那么apt-get install会进行dnotify.其他发行版可能有类似的东西 –
我想在新文件复制到特定目录时自动运行脚本.换句话说,Linux中是否有一种方法可以“监视”目录以进行更改,然后运行某些内容以响应更改?

解决方法

如果你很幸运能够使用基于debian的发行版,那么apt-get install会进行dnotify.其他发行版可能有类似的东西 – 寻找dnotify名称.

dnotify is a simple program based on Linux kernel 2.4.19+’s dnotify API.
dnotify can execute a specified command each time the content of a specific
directory changes. It is run from the command line and takes two arguments:
one or more directories to monitor and a command to execute whenever a
directory has changed. Options control what events to trigger on: when a file
was read in the directory,when one was created,deleted and so on.

如果您想在自己的程序中处理此问题,则dnotify也是您要使用的API.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读