Posts Tagged 'calendar'

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.