1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Ubuntu環境でinotifywaitを使いファイル更新時に特定のコマンドを実行する方法

Last updated at Posted at 2019-04-04
# install
sudo apt install inotify-tools

# /tmpにあるaaaとbbbのフォルダ以下のファイルが更新されたら、echoが出力される
inotifywait -e create,delete,modify,move -mr /tmp/aaa /tmp/bbb |while read;do while read -t 0.3;do :;done;echo "aaa";done

あまりに覚えづらいので、関数定義をbashrcとかに入れておくと良いかも(alias登録だとダメだったので、関数にしました)

cat << 'EOS' >> .bashrc
# シングルフォルダ:d-watch /tmp/aaa 'echo aaa'
# 複数フォルダ:d-watch '/tmp/aaa /tmp/bbb' 'echo aaa'
function d-watch(){
  inotifywait -e create,delete,modify,move -mr $1 |while read;do while read -t 0.3;do :;done; $2 ;done
}
EOS

LinuxOSなら、どのディストリビューションでも出来ると思う。

完全に余談ですが、d-watchという命名ですが、個人的にalias系のコマンドが他とかぶらないようにするため、daijinloadの頭文字を取って、d-で始めているというのが理由です。

### 登録しているものは、こんな感じっす
alias d-open="xdg-open ."
# alias d-tom="ps -ef | grep tomcat | grep -v 'grep' | awk {'print \$2'} | xargs kill -9"
alias d-push='git push origin `git rev-parse --abbrev-ref HEAD`'
alias d-push-f='git push -f origin `git rev-parse --abbrev-ref HEAD`'
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?