Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect directory changes in unix

How could I track changes of specific directory in UNIX? For example, I launch some utility which create some files during its execution. I want to know what exact files were created during one particular launch. Is there any simple way to get such information? Problem is that:

  1. I cannot flush directory content after script execution
  2. Files created with the name that has hash as a compound part. There is no possibility to get this hash from script for subsequent search.
  3. There could be several scripts executed simultaneously, I do not want to see files created by another process in the same folder.

Please notice that I do not want to know whether directory has been changed as stated here, I need filenames which ideally could be grepped to match specific pattern.

like image 715
altern Avatar asked Mar 03 '10 10:03

altern


People also ask

How do I watch changes in a folder?

We can use the inotifywait command to monitor a directory tree. To monitor a directory tree, including its subdirectories, we'll use the -r parameter. Also, we have to use the -m parameter. This configures inotifywait to keep watching the directory forever.

How do I monitor a directory in Linux?

Watching Files and Directories with Watchman in Linux To watch a directory (e.g ~/bin ) for changes, run the following command. The following command writes a configuration file called state under /usr/local/var/run/watchman/<username>-state/, in JSON format as well as a log file called log in the same location.


1 Answers

You need to subscribe to file system change notifications.

like image 56
Hassan Syed Avatar answered Sep 29 '22 16:09

Hassan Syed