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 example sages of the Linux cal command.
Basic syntax
The cal command takes the following command syntax:
$ cal month year
Linux cal command without arguments
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 18th May 2021
$ cal
Print a month of the year with cal command
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 10th month of 2021, run the command:
$ cal 10 2021
This prints out the calendar dates for the 10th month ( October ) only.
Alternatively, you can invoke the -m option followed by the month of the year. If the year is not provided as an argument, then the month of the current year is printed instead.
$ cal -m June
Print current month alongside previous & following month
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
$ cal -3
Print the entire calendar of the current year
To print the entire traditional calendar for the current year run:
$ cal -y
For instance, to view the calendar of a different year, for example, 2022, specify the year after the cal command as shown.
$ cal 2022
These are some of the commonly used cal command examples. However, if curiosity gets the better of you, find more command options by visiting the cal man pages as shown.
$ man cal
Summary
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.
View the full article