cal Command in Linux



cal is a command-line utility in Linux that lets us fetch the calendar quickly. By default, this command retrieves the calendar of the current month directly in the terminal. However, you can use different options with this command to customize its output according to your requirements or preferences.

Table of Contents

How to Install cal Command in Linux?

The cal command is typically pre-installed in most Linux distributions. However, if it is not installed by default, you can use a package manager to install it on your Linux distribution.

To install the cal command on Debian-based systems, you can use the apt package manager as follows −

sudo apt install ncal
Install cal Command in Linux

To install Red Hat, CentOS, or RHEL, use the yum package manager as follows −

sudo yum install ncal
or
sudo yum install util-linux

To install cal on Fedora, simply run the following command −

sudo dnf install util-linux

Similarly, you can install the cal command on Arch Linux or Manjaro using the Pacman package manager, as follows −

sudo pacman -S util-linux

How to use cal Command in Linux?

The cal command is a shorthand for "calendar" and is used in Linux to display the calendar for a particular month or an entire year. To use this command in Linux, you can employ the below-mentioned signature −

cal [[month] year]

In the above syntax −

  • cal is a command itself that can be executed without any arguments.
  • "-mjy" represents optional flags. Use "-m" to get the calendar for the current month, "-j" to get the Julian dates, and "-y" for the entire year.
  • The month and year are optional flags that are used to get the calendar of a specific month or a year, respectively.

To learn more about the cal command and its different options, you can explore its manual page using the following command −

man cal
Use cal Command in Linux

Getting the Current Month’s Calendar

We can use the cal command without any parameter, as shown in the following example:

cal

In such a case, this command retrieves the current month’s calendar as illustrated in the following output −

Getting the Current Month’s Calendar

Getting the Current Year’s Calendar

You can execute the cal command with the "-y" flag to the calendar of the entire current year −

cal -y
Getting the Current Year’s Calendar

Getting the Calendar of a Specific Year

Suppose you want to get the complete calendar of the year "2012". For this purpose, you can specify the year number with the cal command as follows −

cal 2012
Getting the Calendar of a Specific Year

Getting the Calendar of a Specific Month of the Specific Year

To get the calendar of a specific month of the specific year, you need to specify the year number followed by the month with the cal command. For example −

cal 2 2014
Getting Calendar of Specific Month of Specific Year

Getting a Three-Month Calendar

You can also get a three-month calendar in Linux using the cal command. In such a case, the calendar includes the present month, the preceding month, and the following month. Here is the demonstration −

cal -3
Getting a Three-Month Calendar

Customizing the Week's Start Day

By default, the week starts from "Sunday", however, you can start a week on the day of your choice. For this purpose, you need to use the "ncal" command instead of the "cal" command. This is because, in most Linux distributions, the cal command doesn't have a built-in option to specify a different day as the starting day of the week.

For instance, the following command will start a week from Monday −

ncal -M
Customizing the Week's Start Day

Getting the Calendar in a Specific Locale

To display the calendar on Linux in a specific locale, first, you need to confirm if your system has that language support and if the necessary locale settings are configured. For this purpose, first, execute the following command −

locale -a | grep hi_IN

If the output shows something like this "xx_xx.UTF-8", it means that the specified locale is available and installed on the system. However, if there is no output as shown in the following screenshot, this means that the specified locale is not available among the installed locales −

Getting the Calendar in a Specific Locale 1

In such a case first, you must install the desired locale on your system and then configure it. For example, executing the below-mentioned command will install the language pack for Hindi on your system −

sudo apt install language-pack-hi
Getting the Calendar in a Specific Locale 2

After installing the desired language pack, you can verify if it's available on your system or not using the following command −

locale -a | grep hi_IN
Getting the Calendar in a Specific Locale 3

The output shows that the specified locale is available and installed on the system. Now run the following command to get the calendar for a specific month in Hindi −

LC_TIME=hi_IN.utf8 cal 1 2023
Getting the Calendar in a Specific Locale 4

Getting the Calendar with Julian Dates

By default, the cal command retrieves the calendar in Georgian calendar format. However, you can also get it in the Julian calendar format. In the Julian calendar format, the date does not reset to 1 at the end of each month.

For instance, after January 31st, February directly begins as 32nd February rather than 1st February. To use the Julian calendar format, you must use the "cal" command with the "-j" flag as shown in the following command −

cal -j
Getting the Calendar with Julian Dates

This sums up the use of the cal command in Linux.

Conclusion

The cal command in Linux offers a straightforward yet versatile way to access and customize calendars directly from the terminal. Users can retrieve calendars for the current month, detailed year overviews, or specific calendars in different languages or formats.

Exploring the functionalities of the cal command enables users to efficiently manage schedules, plan events, and seamlessly integrate calendar data into their workflow. In this article, we demonstrated several examples to explain the working of the cal command in Linux.

Advertisements