Harness the Combinatoric Power of Command-Line Tools and Utilities

../Videos

The Cal Command

Commands Bash

Published January 27, 2019

Display a quick calendar from your command line.

Transcript

Hey all, this is Brian and I want to show you the cal command. It’s a great little utility that you’ve already got installed on your mac or linux machine.

You already know that you can use the date command to get today’s date on the screen.

But sometimes you need to get a look at the week, month, or year. Rather than switching away to your phone, your calendar app, or finding a paper calendar, use the cal command instead.

cal
    January 2019
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

That’s handy. You can also get a calendar for the whole year:

cal 2019

My birthday is in October, so I want to see what October looks like, so I can do that by specifying the month and year:

cal october 2019
    October 2019
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

The ncal command rotates the calendar:

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

If you use the -w switch, ncal will display the week numbers too.

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

These commands print text to the screen, but remember you can use redirection to save them to a file, or even use them in a startup script to display a calendar when you log in.

When you’re already in the Terminal, the cal and ncal commands can save you a small bit of time. Reach for them next time you need to confirm a day and date.