Someone please help me to run the script to maintain a Job: Which can be run for every one hour and should maintain the last two hours files only. It should delete the rest of the files in a dir.
find /<path to your files> -name * -mmin xyz -exec /bin/rm -f '{}' \;
For example:
find . -mtime 0 # find files modified between now and 1 day ago
# (i.e., within the past 24 hours)
find . -mtime -1 # find files modified less than 1 day ago
# (i.e., within the past 24 hours, as before)
find . -mtime 1 # find files modified between 24 and 48 hours ago
find . -mtime +1 # find files modified more than 48 hours ago
find . -mmin +5 -mmin -10 # find files modified between
# 6 and 9 minutes ago
If you, yourself, the person for whom this task matters, cannot be bothered to try, why should any of us invest our time? Especially when there is no indication that you have taken any initiative to read the cron-related manual pages, or to search the web for a tutorial, or even to write a single line of code as a first attempt at a solution.
You'll find that most members are more willing to devote their valuable time to those that help themselves. Read some of the documentation, make an attempt to solve the problem, demonstrate this by posting your script and error messages, and we will be happy to help you with specifics.