Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can iNotify tell me where a monitored file is moved?

Tags:

linux

inotify

I want to monitor a file while it's moving in the system. Can iNotify tell me its new position whenever it's moves?

like image 445
Amanda Avatar asked Sep 16 '25 00:09

Amanda


1 Answers

If you're watching both the directory the file was moved from, and the directory the file was moved to, then you will receive an IN_MOVED_FROM event on the source directory and an IN_MOVED_TO event on the target directory, both with the same cookie. You can then use the name fields of the two events to find out where the file was moved to and from.

If you're only watching the source directory, or only the target directory, then you will only get one of the events, so you will only have half of the info. This is a limitation of inotify.

like image 90
hobbs Avatar answered Sep 17 '25 19:09

hobbs