When working exclusively in a Linux terminal environment, checking the date or verifying which day of the week a specific date falls on usually involves reaching for your smartphone or switching to a graphical desktop interface. However, the Linux command line includes a built-in calendar utility that is faster and more efficient than opening a separate app. The cal command prints a neatly formatted text-based calendar directly to your standard output, allowing you to quickly reference dates without breaking your command-line workflow.
Displaying the Current Month
The most basic usage of the command requires no flags or arguments.
- Open your terminal application.
- Type the command:
cal - Press Enter.
The terminal will print a standard calendar grid for the current month. The current day is usually highlighted with a coloured background or inverted text (depending on your terminal emulator’s colour scheme). The grid aligns the days of the week starting with Sunday on the left, matching the standard North American calendar format.
Displaying Specific Months and Years
The true power of the cal command is its ability to instantly generate calendars for past or future dates, making it an excellent tool for quick historical reference.
- Displaying an entire year: If you want to see all twelve months of the current year at a glance, run:
cal -y - Displaying a specific past/future year: If you want to view the entire calendar for the year 2025, simply append the four-digit year to the command:
cal 2025 - Displaying a specific month in a specific year: If you need to know what day of the week July 4th fell on in the year 1999, provide the month number (1-12) followed by the year:
cal 7 1999
Advanced Formatting Flags
Depending on your region or specific needs, the default Sunday-start grid might not be ideal. The cal command (and its closely related, more modern variant ncal, which is often aliased to the same binary on Ubuntu systems) offers several formatting flags.
- Start the week on Monday: If you prefer the European ISO 8601 standard where the week begins on Monday, use the
-mflag:cal -m - Display the Julian calendar format: If you need to know the numerical day of the year (from 1 to 365) rather than the date of the month, use the
-jflag:cal -j
(For example, February 1st will display as day 32). - Display the previous, current, and next month: If you are planning a schedule that bridges the end of the current month and the beginning of the next, the
-3flag is incredibly useful. It prints three side-by-side calendars: last month, this month, and next month:cal -3
Piping Calendar Output
Because the calendar is just plain text, you can pipe it into text files for documentation purposes. For example, if you are writing a project plan in a text file and want to append the calendar for next month to the bottom of the document, you can use the standard append redirector:
cal 10 2024 >> project_plan.txt