Working with calendars in a Linux terminal

The Calendar graphical tool available on your Ubuntu system is quite useful. However, if you are more experienced in the terminal, you can use powerful command line utilities such as cal and ncal to customize how calendars are viewed for a specific month or year. This article explains in detail the cal and ncal commands along with options that you can use with them.

We ran the commands and procedures mentioned in this article on the Ubuntu 18.04 LTS system.

Since you will use the Linux terminal to view customized calendars, you can open it using Dash or the keyboard shortcut Ctrl + Alt + T.

Cal command

The cal utility displays the calendar in the traditional horizontal format. The following simple cal command is used to view the calendar for the current month with the current date highlighted:

$ cal

Cal Command Options

You can view the calendar according to the following syntax, based on the options described below:

$ cal [-m [month]] [-y [year]] [-3] [-1] [-A [number]] [-B [number]] [-d [YYYY-MM]] [-j]
optionusing
-m [month]Use this option to display the calendar for the specified month. You can specify the full name of the month, for example, “January,” or a three-letter abbreviated form, for example, “January.” In addition, you can also specify the month number using this option. This switch also gives you the ability to view the calendar for the month of next year; in this case, you can add the letter f after the month number, for example -m 1f
-y [year]Use this option to view the calendar for the specified year. For example, “-y 2019” will display all months for 2019
-1Use this option to view the calendar for only one month. Since this is the default setting, you can avoid using this switch unnecessarily.
-3Use this option to view calendars for three months; These include the current month, previous month, and upcoming month.
-AND [number]Use this option if you want to view the number X of upcoming months along with the calendar that you have already set for viewing.

Example 1: cal -3 -A 1 (this command displays the calendar for the current, previous and next month, as well as another 1 month after the next month)

Example 2: cal -y 2019 -A 1 (this command displays the calendar for 2019 along with another month, i.e. from January to 2020

-B [number]Use this option if you want to view the X number of previous months along with the calendar that you already set to view.

Example 1: cal -3 -B 1 (this command displays the calendar for the current, previous and next month, as well as another 1 month before the previous month)

Example 2: cal -y 2019 -B 1 (this command displays the calendar for 2019 along with one month of the previous year, i.e. December for 2018

-d [YYYY-MM]You can view the calendar for a specific month of a certain year by specifying this year and month in the format YYYY-MM with the -d option.
-jYou can use this option to view the calendar in Julian format, and not in the default Gregorian format.

Cal Command Examples

The following command displays the entire calendar for the current year:

$ cal -y

Show all months of the year with cal

The following command will display the calendar for January 2017, as indicated in the YYYY-MM format in the command:

$ cal -d 2017-01

Show one month with cal

Ncal command

The ncal command is more powerful than the cal command. It displays the calendar in a vertical format with some additional options. These include displaying Easter dates, viewing the calendar from Monday or Sunday as starting days, and much more.

The following simple ncal command is used to view the calendar in vertical format for the current month, highlighting the current date:

$ ncal

Linux ncal team

Ncal Command Options

You can view the calendar according to the following nval syntax based on the options described below:

ncal [-m [month]] [-y [year]] [-h] [-3] [-1] [-A [number]] [-B [number]] [-d [YYYY-MM]] [-C] [-e] [-o] [-p] [-w] [-M] [-S] [-b]

Note. The parameters already explained for the cal command can be used in the same way for the ncal command.

Optionsusing
-hourBy default, the cal command highlights today’s date. However, if you use the -h option, it will not highlight the date.
-eUse this option to view the Easter date for Western calendars.
-aboutUse this option to view the date of Orthodox Easter.
-PUse this option to view country codes and switching days, which are used to switch from Julian to Gregorian calendars for this country.
-wWhen you use this option, ncal will print the week number under each week.
-WITHUsing this option, you can use all the options of the cal command with the ncal command.
-MUse this option to view Monday calendars as the first day of the week.
-SUse this option to view calendars with Sunday as the first day of the week.
-bWhen you use this option, ncal will display the calendar horizontally since it is displayed with the cal command

Ncal Command Examples

The following command displays the calendar for the current month without highlighting today’s date:

$ ncal -h

Highlight today's date on the calendar

The following command will display the calendar of the current month with Monday as the first day of the week.

option ncal -M

Through this article, you learned how to view calendars according to the many options available for the cal and ncal commands. Using these options, you can configure how calendars are viewed instead of the usual way to display calendars on Linux.

Working with calendars in a Linux terminal

Sidebar