Here’s exactly what I want to do: have a script that, upon detecting that a new file has been put into a predefined directory, runs a little filename scan & move algorithm.
Simple example: I choose to monitor /home/myname/Downloads. Say the state of that folder changed, someClass.java was just added. My algorithm decides to send it to /workspace and does it.
Writing the algorithm is easy. What I’m asking is how to make this monitoring happen.
I see 2options:
-find Linux’s own file operations script and add my code there
-have a normal bash script that somehow gets notified and run when stuff happens in folders
Or am I completely off?
To expand upon Ignacio’s suggestion to use incron: Linux provides an
inotify(7)mechanism that allows programs to watch files and directories for modifications. (This was especially nice for KDE and GNOMEexplorer.execlones — allow directory listings to update immediately when new files are added or removed, without a busy-wait constant re-polling for directory contents.)Using
inotify_add_watch(2)directly though is tedious programming. I’m thrilled to findincron(thanks again to Ignacio), it sounds like a perfect reusable tool to make working withinotify(7)easy for everyone in a declarative syntax.