The graphical Calendar tool available on your Ubuntu system is pretty useful. However, if you are more Terminal-savvy, you can use the powerful command line utilities like cal and ncal in order to customize the way you want to view calendars for a specific month or year. This article explains the cal and ncal commands in detail alongwith the options you can use with them.

We have run the commands and procedures mentioned in this article on a Ubuntu 18.04 LTS system.

Since you will be using the Linux Terminal in order to view customized calendars, you can open it through the Dash or the Ctrl+Alt+T shortcut.

The 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

Linux cal command

Cal Command Options

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

$ cal [-m [month]] [-y [year]] [-3] [-1] [-A [number]] [-B [number]] [-d [YYYY-MM]] [-j]
OptionUse
-m [month]Use this option to display the calendar for the specified month. You can specify the entire month name such as “January” or the three letter abbreviated form such as “Jan”. Alternatively, you can also specify the month number with this option. This switch also gives you the option for viewing calendar for a month of the next year; in that case, you can add the letter f after the month number such as -m 1f
-y [year]Use this option in order to view the calendar for a specified year. For example ‘-y 2019’ will display all months for the year 2019
-1Use this option to view the calendar of only one month. Since this is the default setting, you can avoid using this switch unless necessary.
-3Use this option in order to view calendars for three months; these include the current month, the previous month, and the coming month.
-A [number]Use this option when you want to view an X number of coming months along with the calendar you have already set for viewing.

Example 1: cal -3 -A 1 (this command will display the calendar for the current, previous and next month, and also 1 more month after the next month)

Example 2: cal -y 2019 -A 1 (this command will display the calendar for the year 2019 along with one more month i.e. January for 2020

-B [number]Use this option when you want to view an X number of previous months along with the calendar you have already set for viewing.

Example 1: cal -3 -B 1 (this command will display the calendar for the current, previous and next month, and also 1 more month before the previous month)

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

-d [YYYY-MM]You can view the calendar of a specific month of the specific year by mentioning that year and month in YYYY-MM format with -d option.
-jYou can use this option to view the calendar in Julian format rather than the default Gregorian format.

Cal Command Examples

The following command will display 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 it is specified in the YYYY-MM format in the command:

$ cal -d 2017-01

Show one month with cal

The ncal Command

The ncal command is more powerful than the cal command. It displays the calendar in a vertical format with some more additional options. These include displaying the date of Easter, viewing calendar with 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 with the current date highlighted:

$ ncal

Linux ncal command

Ncal Command Options

You can view the calendar according to the following nval syntax, based on the options explained 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 options already explained for the cal command can be used in the same manner for the ncal command.

OptionsUse
-hBy default, the cal command highlights today’s date. However, if you use the the -h option, it will not highlight the date.
-eUse this option to view the date of Easter for western calendars.
-oUse this option to view the date of the Orthodox Easter.
-pUse this option to view country codes and switching days that are used for switching from Julian to Gregorian calendars for that country.
-wWhen you use this option, ncal will print the week number under each week.
-CBy using this option, you can use all the options of the cal command with the ncal command.
-MUse this option to view calendars with Monday 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 as it is displayed through the cal command

Ncal Command Examples

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

$ ncal -h

Highlight todays date in calendar

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

ncal -M option

Through this article, you have learned to view calendars according to the many options available for the cal and ncal commands. By using these options you can customize the way you want to view calendars instead of the usual way calendars are displayed in Linux.

 

Working with Calendars in the Linux Terminal