cal – A command line calendar

If you already know about cal then you can move along, but if not please allow me to share this hidden gem with you.

(I find that the *nix command line is peppered with commands like this which are amazingly useful, and if you come from a *nix background they will be second nature to you. If, like me, you are a refugee from another OS, you may not have found some of them yet.)

With cal, it’s easier to show what it does than to explain it.

[~] $ cal
      May 2010      
Mo Tu We Th Fr Sa Su
                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

cal by itself gives you a calendar for the current month.

[~] $ cal -3
     April 2010             May 2010              June 2010     
Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su  Mo Tu We Th Fr Sa Su
          1  2  3  4                  1  2      1  2  3  4  5  6
 5  6  7  8  9 10 11   3  4  5  6  7  8  9   7  8  9 10 11 12 13
12 13 14 15 16 17 18  10 11 12 13 14 15 16  14 15 16 17 18 19 20
19 20 21 22 23 24 25  17 18 19 20 21 22 23  21 22 23 24 25 26 27
26 27 28 29 30        24 25 26 27 28 29 30  28 29 30            
                      31                                        

cal -3 gives you a 3 month view.

What if you want a different month? No problem. cal mm yyyy will do it. Note that you need to use four digits for the year!

[~] $ cal 05 2009
      May 2009      
Mo Tu We Th Fr Sa Su
             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

Finally, cal -y will give you a year’s calendar. I won’t show an example here for reasons of space, but just try it for yourself. Naturally, you can do something like cal -y 2011 too.

There are a couple more options, so as always read man cal for the gory details.

Advertisements

1 Response to “cal – A command line calendar”


  1. 1 Ralph Corderoy 15/05/2010 at 13:43

    “cal -y” gives the current year’s calendar. To get next year’s, do “cal 2011”. The -y isn’t needed here, it always requests the current year but the current code ignores it when a year is specified.

    An aside, before date(1) grew a -d option, parsing cal(1)’s output was a common way to answer date questions in scripts.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s





%d bloggers like this: