0

I have a folder, inside of which there are a lot of files. I was looking for a way to check whether any file inside that folder has been opened or not. If it is open, I need to get notified. I know this can be done using inotify-wait but have not been able to do so.

Here is my script

MONITORDIR="/home/aniketshivamtiwari/Downloads/Projects"
inotifywait -m -r -e create --format '%w%f' "${MONITORDIR}" | while read NEWFILE
do
        echo  "File ${NEWFILE} has been opened" 
done
1

Here is the solution First install sudo apt-get install inotify-tools

MONITORDIR="path/to/the/folder"
inotifywait -m -q -e open --format '%w%f' ${MONITORDIR}/* | while read NEWFILE
do
        echo   "File ${NEWFILE} has been open" 
done

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.