我想在特定文件或目錄更改時(shí)運(yùn)行Shell腳本。我如何輕松做到這一點(diǎn)?
3 回答

三國(guó)紛爭(zhēng)
TA貢獻(xiàn)1804條經(jīng)驗(yàn) 獲得超7個(gè)贊
您可以嘗試entr在文件更改時(shí)運(yùn)行任意命令的工具。文件示例:
$ ls -d * | entr sh -c 'make && make test'
要么:
$ ls *.css *.html | entr reload-browser Firefox
或Changed!在file.txt保存文件時(shí)打?。?/p>
$ echo file.txt | entr echo Changed!
對(duì)于目錄,請(qǐng)使用-d,但您必須在循環(huán)中使用它,例如:
while true; do find path/ | entr -d echo Changed; done
要么:
while true; do ls path/* | entr -pd echo Changed; done
添加回答
舉報(bào)
0/150
提交
取消