cal | grep --before-context 6 --after-context 6 --color -e " $(date +%e)" -e "^$(date +%e)"

Show this month's calendar, with today's date highlighted

Explanation: * The date command evaluated to today's date with blank padded on the left if single digit * The grep command search and highlight today's date * The --before-context and --after-context flags displays up to 6 lines before and after the line containing today's date; thus completes the calendar. I have tested this command on Mac OS X Leopard and Xubuntu 8.10

By: haivu
2009-03-04 06:46:52

These Might Interest You

  • The cal command is handy, but sometimes you want to quickly see today's date highlighted. That's why I came up with this quick command. Much like but cleaner and more succinct. Show Sample Output

    cal | grep -E --color "\b`date +%e`\b|$"
    donjuanica · 2012-06-27 20:30:40 0

  • 0
    cal -y | tr '\n' '|' | sed "s/^/ /;s/$/ /;s/ $(date +%e) / $(date +%e | sed 's/./#/g') /$(date +%m | sed s/^0//)" | tr '|' '\n'
    luishka · 2009-05-26 20:31:26 3
  • Show today date on a yearly calendar.

    cal -y
    andrepuel · 2009-09-02 12:57:23 0
  • Displays a calendar. Show Sample Output

    cal [[month] year]
    raphink · 2009-02-16 15:33:46 0
  • Contrary to logic, typing calendar won't show a calendar, that's the job of cal. Typing calendar will show some trivia related to the current date. Tested against many Linux distros and FreeBSD. Show Sample Output

    vlan7 · 2010-01-29 11:17:11 3
  • the -3 show the previous, current, and next month. Show Sample Output

    cal -3
    haivu · 2009-04-02 17:40:38 2

What Others Think

Why so much .... cal Is sufficient. Current date is highlighted already.
CodSpirit · 481 weeks ago
CodSpirit: Which system are you talking about? I tried cal alone on Mac OSX Leopard and on Xubuntu 8.10 and the current date is not highlighted.
haivu · 481 weeks ago
cal | grep -C6 --color -e " $(date +%e)" -e "^(date +%e)"
macha3162 · 480 weeks and 6 days ago
The cal in OSX doesn't highlight. The one in RHEL (actually "ncal") does. This hack is handy for those cal's that don't highlight.
DEinspanjer · 480 weeks and 5 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: