On linux, how to monitor the change of a file/directory, by system call or shell command?

2.6k Views Asked by At

Under windows programming, there's win32 api that allow us to monitor the status of a file or a directory: when changed, there's event notification for a user callback function. E.g. when creating a directory in one explorer window, other explorer window related with this directory will also be refreshed.

My question: how to do this on linux? Does linux provide any sytem call or posix api or shell command to monitory a file/directory?

I know git can do it, but how does git made it?

Thanks!

1

There are 1 best solutions below

0
On BEST ANSWER

The equivalent Linux API is inotify:

The inotify API provides a mechanism for monitoring file system events. Inotify can be used to monitor individual files, or to monitor directories. When a directory is monitored, inotify will return events for the directory itself, and for files inside the directory.