The β€œcal” Command in Linux [7 Practical Examples]

When you think of a calendar, you think of a GUI application like Google Calendar. Some think viewing the calendar in Linux is a big hassle. Good news! It is not. Let’s say you are sitting alone, suddenly feeling the urge to have a quick peak into the calendar; type the cal command in your terminal, and it’s there. The cal command in Linux comes with many options, so you can customize your output according to your need.

A. Description

The cal command in Linux is a standard Unix and Unix-like operating systems program. It appeared in the 1st version of Unix. It is also available in FreeDos, which Charles Dye developed. There is an alternative of cal available too. It is called ncal. If you don’t define anything, the cal command in Linux will just show you the current month and date (highlighted).

B. Syntax

The syntax of the cal command in Linux is simple. The syntax is cal, followed by one or multiple options and one or multiple arguments.

cal [OPTION]... [ARGUMENT]...

Note: In the above syntax, OPTION, and ARGUMENTΒ  enclosed by square brackets followed by 3 dots represent that multiple options and argument can be utilized simultaneously.

C. Options

There are multiple options available for the cal command in Linux. You can check those by yourself.

man cal

Note: Manual page for both cal and ncal commands is the same. Some of the options may not work for the cal command.

Useful Options

  • -y (shows the calendar of the whole current year with the current date highlighted)
  • -m (used to view the calendar of a specific month of the current year)
  • -3 (shows previous, current, and next months)
  • -j (shows Julian calendar)

Note: The options inΒ Linux CLI (Command Line Interface) are all case-sensitive, So be cautious while using them.

Practical Examples of the β€œcal” Command in Linux

Here I will show you some practical examples of the cal command in Linux. Be sure to practice them all.

Example 1: Calendar of Current Month with Current Date Highlighted Using the β€œcal” Command in Linux

It is the most common use of the cal command in Linux. You can check the calendar in a matter of seconds by following the steps below:

Steps to Follow >

➊ At first open the Ubuntu Terminal.

βž‹ Type the following command in the command prompt:

cal

➌ Now, press the ENTER button.

Output >

You can see the output. In my case, it is January 2023 and the current date is 3 which is highlighted here.Showing calendar of current month using the cal command in Linux


Similar Readings


Example 2: Calendar of Current Year with Current Date Highlighted

You can see the whole year also. I will option β€œ-y” for this purpose. Follow the steps below:

Steps to Follow >

➊ At first open the Ubuntu Terminal.

βž‹ Type the following command in the command prompt:

cal -y

➌ Now, press the ENTER button.

Output >

You will see an output like below. The whole calendar may not fit in the display, scroll down to see that.Showing calendar of whole current year

Example 3: Calendar of a Specific Month of a Specific Year Using the β€œcal” Command in Linux

You can give a specific month and year to the cal command in Linux as arguments. Let’s I want to view the calendar for the month of December of 1971, I will follow the steps below:

Steps to Follow >

➊ At first open the Ubuntu Terminal.

βž‹ Type the following command in the command prompt:

cal 12 1971

➌ Now, press the ENTER button.

Output >

As you can see, the month of December 1971 is displayed in the terminal.Displaying calender using of a specific month of a specific year using the cal command in Linux

Example 4: Calendar of Specific Month of Current Year

This example can be useful for a lot of us. Let’s say you want to know about a certain month of the current year. Then, type option β€œ-m” followed by the name of the month like the following:

Steps to Follow >

➊ At first open the Ubuntu Terminal.

βž‹ Type the following command in the command prompt:

cal -m February

➌ Now, press the ENTER button.

Output >

Now I am seeing the month of February of the year 2023 even though I am in January.Calender of a specific month of current year

Example 5: Calendar of a Specific Whole Year Using the β€œcal” Command in Linux

Using the cal command in Linux, you can also view a certain whole year. Just do the following:

Steps to Follow >

➊ At first open the Ubuntu Terminal.

βž‹ Type the following command in the command prompt:

cal 2022

➌ Now, press the ENTER button.

Output >

In this case, too, the calendar may not fit in the display. You need to scroll down.Showing calendar of a specifc whole year using the cal command in Linux


Similar Readings


Example 6: Calendar Showing Previous, Current and Next Months

To have a view of the calendars of past, present, and future months altogether, you can use the option β€œ-3”. Then proceed like the following:

Steps to Follow >

➊ At first open the Ubuntu Terminal.

βž‹ Type the following command in the command prompt:

cal -3

➌ Now, press the ENTER button.

Output >

As I am in January, my previous month is December and the upcoming month is February. It is shown perfectly on the display.Showing past, present and future months

Example 7: Julian Calender Using the “cal” Command in Linux

The calendar you see and use in your day-to-day life is the Gregorian Calendar. However, you can view Julian’s calendar by using the cal command in Linux. I will use the option β€œ-j”. Also, I want to view the calendar for the month of February, so I will use the option β€œ-m” as well. Now, Follow the steps below:

Steps to Follow >

➊ At first open the Ubuntu Terminal.

βž‹ Type the following command in the command prompt:

cal -jm February

Note: Putting β€œm” before β€œj” will generate an error asΒ option β€œ-m” requires anΒ argument.

➌ Now, press the ENTER button.

Output >

I have shown both Gregorian and Julian here, and the difference is apparent. In Gregorian, February starts as 1,2,3….. whereas in Julian, it is starting as 31,32,33…..Displaying Julian Calendar using the cal command in Linux

What to Do If β€œcal” Command Doesn’t Work Properly

If you face any issues regarding the cal command in your machine, the following might help.

For example, the current date isn’t highlighted in my terminal.Calendar without current date highlighted

It can be solved by the steps below:

Step 1: Download the β€œcal” file from below and go to that directory.

Step 2: Make it β€œexecutable” for all users (if necessary).

chmod a+u cal

Step 3: Delete the current existing β€œcal” file. Type your password (if necessary).

sudo rm /usr/bin/cal

Step 4: Now move the new β€œcal” file to any bin folder.

sudo mv cal /usr/bin/cal

I have also attached an image for you. See the current date highlighted now.Showing steps to follow if cal command doesn't work properly

Conclusion

The cal command in Linux is a handy tool to have. You can use it on a daily basis. Hopefully, the examples shown here are enough for you. Practice more, surely you will be proficient in using the cal command in Linux.


Similar Readings

Rate this post
LINUX
FUNDAMENTALS
A Complete Guide for Beginners Enroll Course Now
Walid Al Asad

Hello Everyone! I am Walid Al Asad. Currently, I am working at a tech company named Softeko as a Linux Content Developer Executive. I live in Dhaka, Bangladesh. I have completed my BSc. in Mechanical Engineering from Bangladesh University of Engineering and Technology (BUET). You can find me on LinkedIn, and ResearchGate. Read Full Bio

Leave a Comment