Command-line gems: cal & ncal

Jul 12, 07:42 am

A few weeks ago I blogged about the potential to live your life at the command-prompt. Forget about graphical niceties; it’s just you, a dollar prompt and a blank screen.

If you’ve decided to make the switch then you might be interested in cal and ncal.

To quote the man page, these two utilities “display a calendar and the date of Easter”. I’m not sure why the fascination with Easter, or even why there’s a Christian bias, but cal is a utility I use on a regular basis to help me schedule.

The difference between ncal and cal is primarily down to formatting. With ncal the axis are reversed. Here’s a month view from ncal:

ncal:
July 2006
Mo     3 10 17 24 31
Tu     4 11 18 25
We     5 12 19 26
Th     6 13 20 27
Fr     7 14 21 28
Sa  1  8 15 22 29
Su  2  9 16 23 30

... and here’s the same thing via cal:

cal:
July 2006
Su Mo Tu We Th Fr Sa
                   1
 2  3  4  5  6  7  8
 9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31

Using cal and ncal is a piece of cake. Simply specify a month and/or a year to get a monthly calendar. For example, to find out what day my sister’s birthday falls on in the year 2041, I can type:

cal june 2041

To find what her birthday would be had she been a contemporary of Jesus, I can type:

cal june 1

This will show be the days in the month of June in 1AD. There are certain caveats about Gregorian/Julian calendar change-over dates that you might need to take into account if you seriously want to know the dates back in time—see the man page for details.

For a whole year’s calendar, just specify the year:

cal 2007

To view the previous month, the current month and the following month, use the -3 command option:

cal -3


    1. agnostic says:

      “I’m not sure why the fascination with Easter,…”

      The point is that the Easter date (not the day of the week – it is always Sunday) is not fixed and should be calculated with the use of the Gausse formula which apparently is encoded in cal.




Add your comments

Please keep your comments relevant to this blog entry: inappropriate or purely promotional comments may be removed. To add hyperlink, please follow this example: "your link text":http://your.link.url