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.
cal [-3 | -y | -m] [[MONTH] YEAR]
Try 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.
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
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
cator use-N/--color=neverto remove the escape codes before processing the text. - Calendar reform: some versions of
calreproduce 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) orncal; on Fedora inutil-linux.ncalis 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 usedate -d ... +%A. Seedate. - Locale: month and day names follow
LC_TIME, seelocale.
Related
date,timedatectl,locale- Lessons: printf and date, Loops