我每次在Linux中保存文件时如何运行脚本?

我每次在Linux中保存文件时如何运行脚本?

Linux有一个子系统调用inotify ,这可能导致文件系统将文件系统中的变化报告给应用程序。

你的linux系统可能有一个名为incron的包,这使得使用inotify非常容易。 (或者搜索你的可用软件包,查找包含“inotify”这个词的任何软件包)。

设置incron与设置cron非常相似,除非cron在指定的时间和日期执行脚本, incron在指定的文件或目录更改时执行脚本。

PS。 在Ubuntu(例如), incron是这个包,并与安装

 sudo apt-get install incron 

我试图做同样的事情,最后写了一个python脚本来为我做。

https://github.com/bawigga/spy

用法:

 $ ./spy myscript.py ... your script output ... $ ./spy --help Usage: spy [OPTIONS] [WATCH] Options: --version show program's version number and exit -h, --help show this help message and exit -c, --clear clear the screen after each execution -e COMMAND, --exec=COMMAND path to the program to execute -i INTERVAL, --interval=INTERVAL (in seconds) set the time interval to check for file modifications