Most users naturally think of the calendar on their computer as a GUI application, or something that is displayed directly from the desktop. But it’s also possible to use the cal command in Linux to view the calendar through the command line terminal.
If you usually use a desktop environment on Linux, or you’re coming from a Windows or MacOS operating system, you probably think this is an overly complex way of viewing the calendar. But using the cal command in Linux is very simple and actually one of the quickest ways to take a peek at the calendar.
In this tutorial, you’ll learn how to use the cal command in Linux through examples. Follow along below to learn about the various options that you can use with this command.
In this tutorial you will learn:
- How to use the cal command on Linux
|Category||Requirements, Conventions or Software Version Used|
|System||Any Linux distro|
|Other||Privileged access to your Linux system as root or via the
|Conventions||# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – requires given linux commands to be executed as a regular non-privileged user
Frequently Used Options
The cal command displays in its output the day, month, and day of the week on the calendar in the command line terminal. Unlike many other Linux commands, the cal command does not come with a lot of options. But there are a couple that are very much worth committing to memory. We’ll cover all of them below in the following section.
cal command in Linux Basic Examples
- Running the cal command by itself, without any additional options, will just print the calendar in the Linux terminal.
As you can see in the screenshot above, the calendar is printed in the cal command’s output. But you might have noticed that the calendar that the cal command displayed only shows the month of September. This is because, by default, the cal command only displays the current month in the calendar when used without any additional options.
- One of the very few command line options that are available for the cal command is the
-yoption. If we pass this command line option to the cal command, we can get it to print in its output a calendar containing every month of the current year in our Linux terminal. The current date will be highlighted in this output as well.
$ cal -y
As you can see in the screenshot above, the cal command prints a calendar containing every month with each day of the week included, with our current date highlighted.
- There is a nifty trick that we can utilize to get the cal command to print calendars of a month of our choosing. Do this by simply specifying the month and year after your cal command.
$ cal 08 2019
We can use the syntax in the above example to print a calendar of a specific month and year, which is August 2019 in our example. As you may have noticed, there is no highlighted date in the calendar of this output. That’s because the cal command only highlights the current date, which our example doesn’t include.
- Running the cal command by itself followed by a specified year will print a calendar of that entire year’s months.
$ cal 2019
As you can see in the screenshot above, the output will display a full calendar of the entire year of 2019.
- We can also use the
-3command line option with the cal command to display a calendar of the previous month, the current month, and the next month of the current year. This is a very handy option as it can cover, all in one command, multiple situations in which you need to see a certain kind of calendar.
$ cal -3
- We can also use the cal command to print for us a calendar of the current month in a different calendar format from the default Georgian calendar format. When the cal command is run with the
-jcommand line option, it will print a calendar in its output of the current month in the Julian calendar format.The Julian calendar format will list every day of each month, counting from 1 to 365, instead of resetting to 1 after every month. This is particularly useful for quickly viewing how many days throughout a year have passed since a specific date.
$ cal -j
You can always use the man command to read more about the cal command and its official documentation. Click the previous link to see how to open the manual pages for any command on a Linux system.
In this tutorial, we learned all about the cal command on Linux which is beneficial to master for general users and system administrators that frequently use the Linux command line terminal and don’t want to use a desktop environment for something simple like viewing a calendar. It is a perfect example of how Linux can take such a simple concept like viewing the calendar and expanding upon it for various situations using a few command line options.