Sometimes, you might want to have a peek at the year’s calendar or even narrow it down to a month’s calendar. The Linux cal command is an excellent built-in tool that displays a calendar of a given year or month depending on the options passed.
In this brief guide, we explore a few examples of the Linux cal command.
- How Does cal Command Work?
- How to Install the cal Utility on Ubuntu 20.04
- How to Use the cal Command
- Print a Month of the Year
- Print the Previous, Current, and the Next Months
- Print the Entire Calendar of the Current Year
- Print the Calendar of the Specified Year
Let’s start the cal command.
How Does cal Command Work?
In Linux and Unix-like systems, the “cal” is a command-line utility that prints the calendars on the terminal. “Cal” is an abbreviated form of Calendar. It is a pretty simple command and doesn’t contain many options. There are a few options to display – year, month, or date – on the console.
How to Install the Cal Utility on Ubuntu 20.04
To install the “cal” command on Linux operating system, launch the terminal and type the following command:
How to Use the cal Command
The cal command takes the following command syntax:
In its basic format, the cal command prints out the current month and highlights the present day. For instance, by the time I’m writing this, the date is December 17, 2022.
Example 1: Print a Month of the Year
To print a specific month of the year, provide the numeric value of the month [ 1 – 12 ] followed by the year.
For example, to display the first month of 2023, run the following command:
This prints out the calendar dates for the first month (January) only.
Alternatively, you can invoke the -m option followed by the month of the year. If the year is not provided as an argument, the month of the current year is printed instead.
Example 2: Print the Previous, Current, and the Next Months
Let’s try out something more ambitious. The cal command also allows you to print the previous, current, and the next month. Simply pass the -3 option at the end.
Example 3: Print the Entire Calendar of the Current Year
To print the entire traditional calendar for the current year, run the following command:
Example 4: Print the Calendar of Specified Year
To view the calendar of a different year, for example 2024, specify the year after the cal command as shown in the following:
These are some of the commonly used cal commands. However, if curiosity gets the better of you, find more command options by visiting the cal man pages using the following command:
The “cal” command is a quite helpful command that is used to display a calendar on the terminal in Linux and Unix- like systems. The Linux cal command displays a simple calendar that allows you to view the current month of the year, the entire current year, or other months or years, depending on your command arguments.