TL;DR: inotifywait -m -e close_write -e delete -e move $(pwd)


Example output under different conditions:

touch foo && echo ... > foo

/path/to/watched/dir/ CLOSE_WRITE,CLOSE foo

mv foo bar

/path/to/watched/dir/ MOVED_FROM foo
/path/to/watched/dir/ MOVED_TO bar

rm bar

/path/to/watched/dir/ DELETE bar

Text editors

This is where things get interesting

vim

/path/to/watched/dir/ CLOSE_WRITE,CLOSE foo

Boring, right? However, let’s do :set backup and try again:

/path/to/watched/dir/ CLOSE_WRITE,CLOSE 4913
/path/to/watched/dir/ DELETE 4913
/path/to/watched/dir/ MOVED_FROM foo
/path/to/watched/dir/ CLOSE_WRITE,CLOSE foo

wut?

emacs

/path/to/watched/dir/ CLOSE_WRITE,CLOSE foo
/path/to/watched/dir/ DELETE .#foo

.#foo is never created, yet deleted.

vscode

/path/to/watched/dir/ CLOSE_WRITE,CLOSE asdf
/path/to/watched/dir/ CLOSE_WRITE,CLOSE asdf

Not sure why it does it twice.