Calendars

Linux has a great command to show a calendar. It is used in a "terminal" or "command line". While that might sound scary, it doesn't need to be. Computer commands in a terminal are both simple and broadly useful.

Get to a terminal screen. In Kubuntu, the fastest route is Alt-F2 to pop up the run command line where you type konsole to get to a terminal screen. You can also get there by way of the application menu under system commands.

Once the terminal window opens, revealing a typically black background with white lettering,
Type: cal

You'll see a compact calendar of the current month with the current day highlighted.

image: cal - one month

You can also get a couple of other expressions of a calendar.
Type: cal -3
and you will see a display of three months, the preceding, current and next months.

image: 3 months

Type: cal -y
and you will get a full year for the current year.

image: full year

Type: cal -j
and you'll see the current month as the count of days from January 1st. As you can see, tax day, April 15th is also day number 105 in a non-leap year.

image: cal -j

Type: cal 5 2010
and you'll see a calendar for the month of May (month number 5 in the 12 month year).

image: select a month

You can get any month of any year, of course, just by choosing the options.
See if you can generate April for the next several years.
Hint: April is month number 4 and next year is 2011 (you didn't need either of those hints, did you. You're sure I'm picking on you, right?

Let's take some steps beyond the command line. For example, what if I want to include a calendar in a document?
I can take screen shots like the ones above, but that's not too elegant.

Look at the next calendar. It is the same text as the screen shot, but it is regular text in this Web page.
     April 2010     
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

I got the text by taking a few extra steps. I began by typing a standard terminal trick to redirect the calendar into a text file.
Type: cal 4 2010
(to get April for 2010) but add more to the command: cal 4 2010 > cal-2010-04.txt
There are spaces on each side of the "greater than (>)" symbol. Using this symbol is called a "redirect", in this case, sending the calendar to a text file instead of the terminal screen (which is also called "std out", standard output).

Looking in the folder/directory where I was as I typed the command, I found the text file created by redirecting the cal command output. I opened the file in a simple text editor. In my case it was kate, which is my text editor of choice. It might be gedit, if I were running the Ubuntu gnome distribution. I copied the text from there, and moments ago, pasted it into this Web page. I'm using Kompozer as my Web page editor. To get the best looking result, I set the style of text to "preformat" instead of the standard "Body Text". If I use Body Text style, I'll lose the spacing that makes the calendar easy to read.

     April 2010    
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  
< Body Text
Text style

You lose the controlled
spacing that lines up the
days of each week.
Preformat >
Text style

You keep the spacing
of the terminal command
output and it looks right.
     April 2010     
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

You can similarly capture any of the versions of the calendar through redirect as I did with the full year in the next illustration. You can paste the calendars into Web pages as I did or into your next word processing document. The uses are up to you.

                             2010                              

January February March
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 1 2 3 4 5 6 1 2 3 4 5 6
3 4 5 6 7 8 9 7 8 9 10 11 12 13 7 8 9 10 11 12 13
10 11 12 13 14 15 16 14 15 16 17 18 19 20 14 15 16 17 18 19 20
17 18 19 20 21 22 23 21 22 23 24 25 26 27 21 22 23 24 25 26 27
24 25 26 27 28 29 30 28 28 29 30 31
31
April May June
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 1 1 2 3 4 5
4 5 6 7 8 9 10 2 3 4 5 6 7 8 6 7 8 9 10 11 12
11 12 13 14 15 16 17 9 10 11 12 13 14 15 13 14 15 16 17 18 19
18 19 20 21 22 23 24 16 17 18 19 20 21 22 20 21 22 23 24 25 26
25 26 27 28 29 30 23 24 25 26 27 28 29 27 28 29 30
30 31
July August September
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 1 2 3 4 5 6 7 1 2 3 4
4 5 6 7 8 9 10 8 9 10 11 12 13 14 5 6 7 8 9 10 11
11 12 13 14 15 16 17 15 16 17 18 19 20 21 12 13 14 15 16 17 18
18 19 20 21 22 23 24 22 23 24 25 26 27 28 19 20 21 22 23 24 25
25 26 27 28 29 30 31 29 30 31 26 27 28 29 30

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


image: CC-BY Reuse of this document is allowed and encouraged using the Creative Commons Attribution 3.0 (or later) license.
Runeman, Algot, (April 15, 2010) Calendars. http://www.runeman.org/tips/linux/calcommand/index.html