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.
Similar Readings
- The βmanβ Command in Linux [6 Practical Examples]
- The “history” Command in Linux [6 Practical Examples]
- The βbcβ Command in Linux [10+ Practical Examples]
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.
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.
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.
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.
Similar Readings
- The βcronβ Command in Linux [3 Practical Examples]
- The βcrontabβ Command in Linux [10 Practical Examples]
- The βdateβ Command in Linux [8+ Practical Examples]
- The βncalβ Command in Linux [8 Practical Examples]
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.
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β¦..
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.
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.
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
- The βneofetchβ Command in Linux [12+ Practical Examples]
- The βtreeβ Command in Linux [14 Practical Examples]
- The βwhatisβ Command in Linux [12 Practical Examples]
- The βwhereisβ Command in Linux [10 Practical Examples]
- The βwhichβ Command in Linux [3 Practical Examples]
- The βatβ Command in Linux [7 Practical Examples]
- The βteeβ Command in Linux [4 Practical Examples]
FUNDAMENTALS A Complete Guide for Beginners