I'm using inotifywait
to keep track of events on a single file (instead of a directory), as
$ inotifywait -m -e open -e close -e move myfile.txt
When I open and edit the file, the logs are printed as expected.
Setting up watches.
Watches established.
myfile.txt OPEN
myfile.txt CLOSE_NOWRITE,CLOSE
But inotify never emits either MOVED_IN
, MOVED_FROM
events (not even DELETE_SELF
) when I rename the file. On the other hand, if I watch the directory containing myfile.txt
, rather than a single file, the events are emitted as usual.
One strange point to me is that, opening and closing the renamed file still log events.
myfile.txt OPEN
myfile.txt CLOSE_NOWRITE,CLOSE
At this point, my file is not myfile.txt
but has another name. Notably, inotify does not track any event evoked working with a newly created myfile.txt
.
My questions are:
How can I correctly track the "renaming" events of a single file with
inotifywait
, while not watching a full directory?How can I get the current name of a single file watched?
--format "%f"
option seems to always print the original file name passed toinotifywait
even though the file is renamed, as shown above.I'm looking for a sort of "rename history logger" that works for a given set of files scattered in the filesystem. Are there any alternatives to inotify, which can be used for this specific purpose?