Monitor a set of files for changes and execute a command on them when they do

后端 未结 4 699
花落未央
花落未央 2020-12-18 10:44

The (command line) interface I have in mind is like so:

watching FILE+ do COMMAND [ARGS] (and COMMAND [ARGS])*

Where any occurrence of \"

4条回答
  •  春和景丽
    2020-12-18 11:15

    You can use entr, e.g.

    ls foo.txt bar.txt | entr sh -c 'rsync -vuar *.txt somewhere.com:. && echo Updated'
    

    Unfortunately you can't check which file has been changed, but using rsync -u will automatically skip files which haven't been changed.

    Here is the second example:

    ls foo.c | entr sh -c 'gcc foo.c && ./a.out'
    

    or simply use make, e.g.

    ls -d * | entr sh -c 'make && make test'
    

    To watch the directory for changes, use -d parameter wrapped inside a shell loop, e.g.:

    while true; do find path/ | entr -d do_stuff; done
    

提交回复
热议问题