Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
4  
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
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.