Home > bash > Calendar of a given month

## Calendar of a given month

Problem

You want to display either the calander of the current month, or the calendar of a specified month. Or, maybe the whole year?

Solution #1

Variations:

```cal           # current month

cal 2011      # year 2011

cal 12 2010   # Dec. 2010 (pay attention to the order: month, then year)
```

Output example:

```    January 2011
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
```

Stupid thing: weeks start with Sunday and there is no way to set it to Monday…

If you want your weeks to start with Monday, you can use `ncal`. However, the layout is different :(

```ncal -M   # start with Monday
```

Output example:

```    January 2011
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
```

Solution #2

If you want to keep the layout of `cal` and you want weeks to start with Monday, `gcal` is the perfect choice.

```sudo apt-get install gcal
```

To make Monday the first day of the week, use the option ‘-s1’. Thus, the output of ‘gcal -s1’ looks like this:

```     January 2011
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
```

You can also add the ‘-s1’ option to the GCAL environment variable to keep this info for every run of `gcal`:

```export GCAL="-s1"
```

(Thanks to Thomas Esken, the author of `gcal`, who explained all this to me when I sent him a mail.)

Solution #3

If you use Gnome, you can call `zenity` to display the calendar in a window. Using the little arrows, you can change months and years.

```zenity --calendar
```

Homework

Figure out what day you were born.