Have you wondered how to show calendar in Linux? Then in this tutorial, we learn about cal command in Linux and its options.
Linux cal command
Cal is a terminal command used in Linux to print a calendar. Simply type cal to display the current month calendar.
Syntax:
cal [options] [[[day] month] year]
If no arguments are provided the cal command displays the current month calendar with the current date highlighted.
Install cal in Linux
Cal is available preinstalled in almost all Linux distributions. In case you are getting command not found error when running cal or from a bash script, possible because ncal is not available.
On Ubuntu/Debian new ncal replaced cal, which comes under bsdmainutils package. You can get cal working by installing ncal.
sudo apt install ncal
Once it's installed cal works as it had a symbolic link to ncal.
How to use cal command
Let's take a look at cal command usage with examples.
Note: The output format may vary slightly depending on the Linux distributions you use. Here we are using Ubuntu
1. To show the calendar of a specific month of the year - for example, "November 2022".
cal 11 2022
2. To show calendar for the current whole year with the current date highlighted:
cal -y
Note: There is some bug preventing cal not to highlight the current date in some Distro, use ncal instead.
3. You can display the whole calendar for a specific year, type:
cal 2022
4. You can display the calendar of previous, current (along with current date highlighted) and next month, type:
cal -3
5. If you wish to display the calendar for the current month and next two months, type
cal -A 2
You may use cal -A 12 to display the calendar for the next 12 months.
vice versa, to display the current month and the previous n months.
cal -B 2
6. To display the current month in the Julian calendar use -j option. Also, it highlights the current Julian date.
cal -j
cal command options
Few available options of cal command:
Options | Description |
---|---|
default | The current month is displayed. |
-y | The same default. |
-3 | Shows the calendar of previous, current, and next month. |
-j | Show Julian the calendar current month. |
-A n | Show the current month and next n months. |
-B n | Show the current month and the previous n months. |
Conclusion
In this tutorial, we have covered cal command in Linux and its options. Thanks for reading.
Navigate all-in-one place of Linux Commands for more learning.
Comments