Cron job that checks for new/recent files

I'm new to shell scripting, and I want to set up a cron job that scans the date/time stamp of all files in a directory, and then if any file is, say, less than 10 minutes old, I want it to execute a command on that file. What would be the best way to go about this? Thanks.

Not sure if it makes a difference, but I'm using Ubuntu 16.04, bash shell.

Welcome DavidHoffman,

I have a few to questions pose in response first:-

  • What have you tried so far?
  • What output/errors do you get?
  • What logical process have you considered? (to help steer us to follow what you are trying to achieve)

There are probably many ways to achieve most tasks, so giving us an idea of your style and thoughts will help us guide you to an answer most suitable to you so you can adjust it to suit your needs in future.

We're all here to learn and getting the relevant information will help us all.

I would suggest creating a marker file that is already 10 minutes old (look at the touch command) and then use find with the -newer flag to look for files newer than your marker file.

I could, of course, just give you an answer but it is better for you to explore and learn a little. Let us know how you get on and if you get stuck we can help further.

Kind regards,
Robin