Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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...

share|improve this question
up vote 1 down vote accepted

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.
share|improve this answer
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 posting your answer, you agree to the privacy policy and terms of service.

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