cal command in Linux with examples

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
cal command in Linux with examples
cal command in Linux with examples
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux distro
Software cal
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

Frequently Used Options



Twitter icon Follow LinuxConfig.org on Twitter for the latest tips and tricks about Linux!


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

  1. Running the cal command by itself, without any additional options, will just print the calendar in the Linux terminal.
    $ cal
    
    Running the cal command to display the calendar in the Linux command line terminal
    Running the cal command to display the calendar in the Linux command line 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.

  2. One of the very few command line options that are available for the cal command is the -y option. 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 
    
    Using the -y option with the cal command to list all of the months of the current year in our Linux command line terminal
    Using the -y option with the cal command to list all of the months of the current year in our Linux command line terminal

    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.

  3. 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.

    Using the cal command to print a calendar of a specific month and year
    Using the cal command to print a calendar of a specific month and year
  4. Running the cal command by itself followed by a specified year will print a calendar of that entire year’s months.
    $ cal 2019
    
    Execution followed by the year 2019 to print a complete calendar of it
    Execution followed by the year 2019 to print a complete calendar of it

    As you can see in the screenshot above, the output will display a full calendar of the entire year of 2019.

  5. We can also use the -3 command 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
    

    Execution followed by the -3 option to display the previous, current, and next month
    Execution followed by the -3 option to display the previous, current, and next month
  6. 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 -j command 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
    


    Running the cal command followed by the -j option to print a calendar of the current month in the Julian calendar format
    Running the cal command followed by the -j option to print a calendar of the current month in the Julian calendar format
NOTE
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.

Closing Thoughts

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.