用 entr 在文件变化时执行命令

把文件列表交给 entr,变化时自动重跑命令。

macOSwatch 重复执行自动化命令行低风险
运行 ls *.py | entr -c python3 app.py,Python 文件变化时重启应用。

01命令

命令
$ ls *.py | entr -c python3 app.py

02作用说明

entr 是一个极小的 Unix 工具,监听标准输入中的文件变化并运行指定命令。-c 在运行间清屏,-d 在新增文件时退出,-r 用于重启长驻进程。

03风险

风险低风险
系统兼容性macOS with Homebrew installed
!注意: 它只监视你列出的文件;新增文件不会自动纳入(除非 glob 重新求值或使用 -d)。

04撤销

✓无需撤销——该命令不会改变持久状态。

05来源

  • Homebrew formula: entr
    Homebrew · vendor-doc · 2026-09-20
    依据: Packages entr, which runs a command when the piped files change.

最后验证: 2026-09-22 · 分类: 开发者