1

I can successfully run this command in the terminal:

find /home/www/files/1 -type f -name '*' -mtime +180 -exec rm {} \

However when I add it as a cron job like so:

*/5 * * * * find /home/www/files/1 -type f -name '*' -mtime +180 -exec rm {} \

It doesn't work and the system sends a mail saying find: missing argument to '-exec'

What can I do to make it work as a cron task?

10
  • use find like this /usr/bin/find in the cron Jan 14 '18 at 1:01
  • Are you sure the first version is working? You appear to have a shell escape \` but no actual character (AFAIK it should be \; - or optionally + if your version of find supports it) Jan 14 '18 at 1:02
  • Yes, the first command works as it's written. I will try adding /usr/bin/find now.
    – Dan P.
    Jan 14 '18 at 1:03
  • 3
    Two additional notes: what do you think -name '*' accomplishes? Also, some versions of find support -delete.
    – dhag
    Jan 14 '18 at 1:24
  • 2
    No, -name '*' is not needed
    – fpmurphy
    Jan 14 '18 at 1:47
2

You are missing the semi colon at the end of the -exec argument.

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