Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

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

I would like to highlight today's date in the output of the cal command. What is the best way?

This is what I have so far:

cal -m | grep -C6 --color "$(date +%e)"

but it doesn't work for all cases e.g, when the date has a single digit. I also want the highlighting to work when I display the calendar for a year.

share|improve this question
what specific version of UNIX are you using and what is the output of echo $TERM ? – jamespo Apr 11 '11 at 14:09
Red Hat Linux / BSD Cal. – dogbane Apr 11 '11 at 14:20
"BSD Cal" is the output of echo $TERM ? – jamespo Apr 11 '11 at 15:21
$TERM is linux. – dogbane Apr 11 '11 at 17:10
What version of Red Hat and cal, e.g. cat /etc/redhat-release and rpm -q util-linux. This works out of the box on recent versions of Ubuntu and Fedora, so presumably you are using an old version. – Mikel Apr 12 '11 at 2:57

I don't know how to highlight the day in the year calendar cal -y with just regular expressions, but the reason your example was not working for single digit dates is because $(date +%e) prepends a space to the output when the date has a single digit.

This will work:

cal | grep --color -EC6 "\b$(date +%e | sed "s/ //g")"
share|improve this answer
in fish: cal | grep --color -EC6 "\b"(date +%e | sed "s/ //g") – Jorge Bucaran Feb 17 '15 at 1:42

On my system (openSUSE 11.4, util-linux-2.19), the current date in output form cal is automatically highlighted (reverse colors) if the output goes to terminal. As per the manpage, this seems to be the default. If it does not work on your system, it might be a bug.

share|improve this answer
There are many variants of cal, for example all three BSDs have different features. This isn't a bug in dogbane's cal, just a different implementation. – Gilles Apr 11 '11 at 19:59

It may be fairly complicated to do something like this;
Why not try something like pal?

share|improve this answer

The output is already highlighted, so you don't need to highlight it manually. In case you want it to work with grep, you need to disable it:

cal -mh | grep -C6 --color "$(date +%e)"
share|improve this answer
cal | grep -C6 --color "\b$(date +%e)\b" ... need the boundary \b otherwise it will highlight chunks of the year too – slf Oct 14 '14 at 13:21

I think you can use the command date +%-e instead of date +%e to remove the space.

share|improve this answer

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.