How can I detect any file or folder is being copied/moved to a directory and then run a shell script?

The files copied/moved would mostly have the same file names as the existing ones...


You should probably use inotify, command line tools provided in inotify-tools package.

Also better should be the package inoticoming. Description:

Description: trigger actions when files hit an incoming directory
 inoticoming is a daemon to watch a directory with Linux's inotify
 framework and trigger actions once files with specific names are placed
 in there.
 For example it can be used to wait for .changes files uploaded
 into a directory and call reprepro to put them into your repository.
  • Thank you, enzotib but is there a work around if I don't want to install a package? If I want to achieve this without any outside packages? – S.M.09 Sep 6 '11 at 21:10
  • In such a case, you should check in a loop the presence of files. – enzotib Sep 6 '11 at 21:12
  • Thats fine until the files that might be copied / moved have different file names to those inside the directory....what for those which have the same name... i.e. those which get overwritten... – S.M.09 Sep 6 '11 at 21:14
  • You could probably check the inode number, with ls -li – enzotib Sep 6 '11 at 21:27

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.