Skip to content
Tutorials Center
My learning

Topics

Linux Command Reference ยท System Information

Linux cal command

Reference for the Linux cal command: print a month, a year or several months, change the first weekday, and build a calendar yourself with date when cal is missing.

cal prints a text calendar: the current month by default, or any month or year you ask for. It is a tiny tool, but handy for checking which weekday a date falls on or how a month lines up.

cal comes from the util-linux or bsdmainutils package and is not installed everywhere (minimal images and containers often lack it). The examples below that run on this site therefore build a month with date, which is always available, so you also learn what cal does underneath.

Terminal
cal [-3 | -y | -m] [[MONTH] YEAR]

Try it

Bash A month calendar built with date (stand-in for cal)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Bash Which weekday is it?

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Syntax

Terminal
cal                  # current month, today highlighted on a terminal
cal 2024             # whole year
cal 3 2024           # March 2024
cal -3               # previous, current and next month
cal -y               # current year
cal -s | -m          # week starts on Sunday | Monday
Option Description
-1 One month (default).
-3 Previous, current and next month.
-y The whole current year.
-s, -m First day of the week: Sunday or Monday (util-linux).
-j Julian days (day of the year).
-w Show ISO week numbers (util-linux).

Returns: 0 on success; non-zero for an invalid month or year. A year given with one argument is read as a year, so cal 12 shows the year 12 and not December. Write cal 12 2024 for the month.

Usage notes

  • Highlighting: when output is a terminal, today is shown in reverse video. Pipe to cat or use -N/--color=never to remove the escape codes before processing the text.
  • Calendar reform: some versions of cal reproduce the historical switch from the Julian to the Gregorian calendar (September 1752 in the English-speaking world), so very old months can look odd. For modern dates this never matters.
  • Not installed? On Debian and Ubuntu it is in bsdmainutils (older) or ncal; on Fedora in util-linux. ncal is the same program with a vertical layout.
  • Scripting: do not parse calendars. To get the number of days in a month use date -d "YYYY-MM-01 +1 month -1 day" +%d; for a weekday use date -d ... +%A. See date.
  • Locale: month and day names follow LC_TIME, see locale.