The Linux 'cal' command


reading time 5 min

Five things you should know about the Linux cal command. There are many, many, more features listed in the man page but these are the ones you should know.

The Unix cal command appeared in 1973 in what was called “Version 5 AT&T UNIX”. Linux and macOS (and all *BSD systems) have very different clones. Check the man page for details.

1. The default is the current month

Run it with no parameters and you get the current month, with today’s date highlighted.

1
2
3
4
5
6
7
8
9
$ cal
    August 2020
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

2. cal -3 shows last and next month too.

The -3 flag shows last, current, and next month. This is typically how I run it. It gives a broad overview and is faster than switching to my browser, opening Google Calendar, and clicking around.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
$ cal -3
                            2020
        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  4                     1         1  2  3  4  5
 5  6  7  8  9 10 11   2  3  4  5  6  7  8   6  7  8  9 10 11 12
12 13 14 15 16 17 18   9 10 11 12 13 14 15  13 14 15 16 17 18 19
19 20 21 22 23 24 25  16 17 18 19 20 21 22  20 21 22 23 24 25 26
26 27 28 29 30 31     23 24 25 26 27 28 29  27 28 29 30
                      30 31

3. cal -y shows the entire year

You can see the entire year with the -y option.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
$ cal -y
                            2020
      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  3  4                     1   1  2  3  4  5  6  7
 5  6  7  8  9 10 11   2  3  4  5  6  7  8   8  9 10 11 12 13 14
12 13 14 15 16 17 18   9 10 11 12 13 14 15  15 16 17 18 19 20 21
19 20 21 22 23 24 25  16 17 18 19 20 21 22  22 23 24 25 26 27 28
26 27 28 29 30 31     23 24 25 26 27 28 29  29 30 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  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
...
...
...
...

4. cal x y shows a month x of year y

I never seem to remember which comes first, the month or the year. If you know of a good mnemonic device to help remember, please post in the comments.

My mother always told me that I was born on a Monday and would sing the nursery rhyme. Here’s how you can verify that I’m really “fair of face”:

1
2
3
4
5
6
7
8
$ cal 12 1968
   December 1968
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

4. cal x shows year x

Given a single numeric paremeter, cal shows the entire year. So, cal 2021 shows (as of this writing) next year’s calendar.

Cal is very literal. cal 21 shows the year 21, not the year 2021.

5. September 2, 1752 is not a bug.

A common trick to play on people is to tell them that you found a bug in and show them September, 1752.

1
2
3
4
5
6
$ cal 9 1752
   September 1752
Su Mo Tu We Th Fr Sa
       1  2 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30

That’s the month that England switched from the Julian to Gregorian Calendar. The two calendars were out of sync by 10 days.

Different countries switched on different months. ncal (“new cal”) knows when different countries changed. Russia didn’t change until 1918!

1
2
3
4
5
6
7
8
9
$ ncal -s RU -3  2 1918
    January 1918      February 1918     March 1918
Mo  1  8 15 22 29       18 25              4 11 18 25
Tu  2  9 16 23 30       19 26              5 12 19 26
We  3 10 17 24 31       20 27              6 13 20 27
Th  4 11 18 25       14 21 28              7 14 21 28
Fr  5 12 19 26       15 22              1  8 15 22 29
Sa  6 13 20 27       16 23              2  9 16 23 30
Su  7 14 21 28       17 24              3 10 17 24 31

You’ll find ncal on FreeBSD, macOS, and other BSD-derived systems. On those, cal and ncal are hard links to the same binary. The binary looks to see which name was used. If it is run as cal it tries to be backwards compatible with the original Unix command. When it is run as ncal it offers more formats and options.




Tom Limoncelli

Tom Limoncelli

Recent Posts


  1. The Greater Fool
  2. Our House
  3. Niklaus Wirth has passed away at age 89
  4. Apple Vision… thoughts
  5. Removing Dead Code From DNSControl

Archive


Categories


Tags


I agree that this website may store my data to personalize my journey in accordance with their Terms & conditions

Powered by Hugo | Theme - YesThatTheme © 2017 - 2024 Tom Limoncelli