I have allready installed cron and here it is

1 0 * * * rm -R /path/to/my/folder/$(date +'%Y-%m-%d' -d "yesterday")

I want to delete every day folder with "Yesterday name" LIKE "2014-12-14"

Here is my ubuntu /var/log/syslog when I execute "grep CRON" command

Dec 16 00:01:01 {SERVERNAME} CRON[21031]: (root) CMD (rm -R /path/to/my/folder/$(date +') Dec 16 00:01:01 {SERVERNAME} CRON[21030]: (CRON) info (No MTA installed, discarding output)


The manpage (man 5 crontab) says:

The entire command portion of the line, up to a newline or % character, will be executed by /bin/sh or by the shell specified in the SHELL variable of the crontab file. Percent-signs (%) in the command, unless escaped with backslash (), will be changed into newline characters, and all data after the first % will be sent to the command as standard input.

So you have to replace every % in your date format with \%:

1 0 * * * rm -R /path/to/my/folder/$(date +'\%Y-\%m-\%d' -d "yesterday")
| improve this answer | |

You can use this command

find /path/to/dir -maxdepth 0 -ctime +1 -exec rm -fr {} +


1 0 * * * find /path/to/dir -maxdepth 0 -ctime +1 -exec rm -fr {} +

Credit Goes Here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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