Super User is a question and answer site for computer enthusiasts and power users. 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

My application creates directories when user performs certain action. These directories are stored on my machine for exactly one hour and than are deleted.

Now I would like to move the 'deleting logic' part of application into a cron job that will run every minute.

Let's say that directories for deletion are located in /tmp/files/. The script should check all directories in this path and delete all that was created one hour ago.

Any help would be appreciated.

Thanks in advance!

** SOLVED **

This will do the trick:

find ./* -mmin +60 -type d -exec rm -rdf {} \;
share|improve this question
If you solved it yourself, please post as an answer and accept it. This prevents solved/answered questions from being bumped unnecessarily. – Bob May 31 '12 at 8:34
If you use Linux and thus GNU find, use + instead of \;. This will be faster and less resource intensive. – Daniel Andersson May 31 '12 at 11:45
up vote 2 down vote accepted

You shouldn't use find ./* because this causes the shell to expand the wildcard before invoking find which will fail if there are too many files.

Instead, you need to pass "./*" to the find command like this:

find . -type d -path "./*" -mmin +60 -exec rm -rf {} \;
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .