Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Since the % has special meaning to cron, how do I use it as part of a command?

I found this page, which mentions piping echo and sed to escape the % and then remove the extra \, but in my case, the command is date, which doesn't accept parameters through STDIN, so this doesn't work:

echo '+\%Y' | sed -e 's|\\||g' | date

I'm thinking I can create a special date script that will output the date in the format I want, and call that instead, but I'm still wondering if it's possible to do it directly in the cron command.


share|improve this question
up vote 3 down vote accepted

The crontab(5) man page says:

Percent-signs (%) in the command, unless escaped with backslash (), will be changed into newline characters, [...]

so you should be able to just escape the % character by prefixing it with a backslash \:

00 15 * * *  user  date '+\%Y'

The \% sequence is processed by cron, so the shell will see the command date '+%Y' which is a correct invocation of date.

share|improve this answer
Hey, how about that, it works... The page I referenced confused me then. – Ivan Oct 12 '10 at 15:24

Your Answer


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.