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

我想在新文件复制到特定目录时自动运行脚本.换句话说,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.

相关文章

linux常用进程通信方式包括管道(pipe)、有名管道(FIFO)、...
Linux性能观测工具按类别可分为系统级别和进程级别,系统级别...
本文详细介绍了curl命令基础和高级用法,包括跳过https的证书...
本文包含作者工作中常用到的一些命令,用于诊断网络、磁盘占满...
linux的平均负载表示运行态和就绪态及不可中断状态(正在io)的...
CPU上下文频繁切换会导致系统性能下降,切换分为进程切换、线...