How to use the command 'cal' (with examples)
- Openbsd
- December 17, 2024
The cal
command is a simple and versatile utility available in Unix-like operating systems. It is primarily used to display a calendar in the terminal. This command is handy for users who want a quick look at a calendar, need to check dates without leaving their command-line environment, or even for simple task scheduling and date verification. The cal
command highlights the current day by default and offers various options, allowing the user to customize the output according to specific needs. Here are several use cases that illustrate the versatility of the cal
command.
Use case 1: Display a calendar for the current month
Code:
cal
Motivation:
This basic use of the cal
command is perfect for when you want a quick glance at the month’s dates. It’s useful for planning purposes where you need to know the current month’s layout—perhaps to count down days to an event, keep track of upcoming commitments, or just to get a sense of the temporal landscape of your current activities.
Explanation: The command has no additional arguments, implying that its default behavior is to show a calendar for the current month of the current year. If today is March 15th, for instance, it will display the whole month of March, indicating the current day.
Example Output:
March 2023
Su Mo Tu We Th Fr Sa
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
(The output will highlight the current date with an asterisk or reverse coloring if supported by the terminal.)
Use case 2: Display a calendar for a specific year
Code:
cal 2025
Motivation: When you need to plan far in advance—possibly for future project planning, setting timelines for tasks that span several months, or even planning personal events like vacations or holidays—a full-year view can be incredibly helpful.
Explanation:
Here, 2025
is the argument specifying the desired year. The command displays all 12 months of the specified year.
Example Output:
2025
January February March
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 4 1 1
5 6 7 8 9 10 11 2 3 4 5 6 7 8 2 3 4 5 6 7 8
12 13 14 15 16 17 18 9 10 11 12 13 14 15 9 10 11 12 13 14 15
19 20 21 22 23 24 25 16 17 18 19 20 21 22 16 17 18 19 20 21 22
26 27 28 29 30 31 23 24 25 26 27 28 23 24 25 26 27 28 29
30 31
April May June
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 4 5 1 2 3 1 2 3 4 5 6 7
6 7 8 9 10 11 12 4 5 6 7 8 9 10 8 9 10 11 12 13 14
13 14 15 16 17 18 19 11 12 13 14 15 16 17 15 16 17 18 19 20 21
20 21 22 23 24 25 26 18 19 20 21 22 23 24 22 23 24 25 26 27 28
27 28 29 30 25 26 27 28 29 30 31 29 30
July August September
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 4 1 2 1 2
5 6 7 8 9 10 11 3 4 5 6 7 8 9 3 4 5 6 7 8 9
12 13 14 15 16 17 18 10 11 12 13 14 15 16 10 11 12 13 14 15 16
19 20 21 22 23 24 25 17 18 19 20 21 22 23 17 18 19 20 21 22 23
26 27 28 29 30 31 24 25 26 27 28 29 30 24 25 26 27 28 29 30
31
October November December
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 4 1 1 2 3 4 5 6
5 6 7 8 9 10 11 2 3 4 5 6 7 8 7 8 9 10 11 12 13
12 13 14 15 16 17 18 9 10 11 12 13 14 15 14 15 16 17 18 19 20
19 20 21 22 23 24 25 16 17 18 19 20 21 22 21 22 23 24 25 26 27
26 27 28 29 30 23 24 25 26 27 28 29 28 29 30 31
Use case 3: Display a calendar for a specific month and year
Code:
cal 7 2024
Motivation:
Sometimes, it’s crucial to check out-of-scope dates to make arrangements or verify scheduling around specific occasions. By specifying both the month and year, the cal
command can show any month’s structure, helping in backward or forward planning, event coordination, and cross-referencing dates.
Explanation:
The first argument 7
indicates July, and the second argument 2024
specifies the year. This will produce the calendar for July 2024.
Example Output:
July 2024
Su Mo Tu We Th Fr Sa
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
Use case 4: Display a calendar for the current year
Code:
cal -y
Motivation: An entire year’s calendar view can be particularly helpful for budget planning, school term schedules, or setting strategic goals that need long-term planning. Visualizing the year at a glance enables more informed decision-making.
Explanation:
The -y
option tells cal
to display the complete current year’s calendar. This option highlights how a single command can transform the cal
utility into a broader planning tool.
Example Output:
2023
January February March
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 4 5 6 7 1 2 3 4 1 2 3
8 9 10 11 12 13 14 5 6 7 8 9 10 11 4 5 6 7 8 9 10
...
October November December
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 4 5 6 7 1 2 3 4 1 2
8 9 10 11 12 13 14 5 6 7 8 9 10 11 3 4 5 6 7 8 9
...
Use case 5: Display Julian days
Code:
cal -j
Motivation: Displaying Julian days is especially useful in scientific communities and industries where timeframes are measured in a continuous count of days. This can be valuable for astronomical calculations, agricultural planning, or when standardizing dates irrespective of the conventional calendar.
Explanation:
The -j
parameter converts the displayed calendar into Julian days format, which starts numbering days from January 1 as day 1 of that year.
Example Output:
October 2023
October 2023
Su Mo Tu We Th Fr Sa
274 275 276
277 278 279 280 281 282 283
284 285 286 287 288 289 290
291 292 293 294 295 296 297
298 299 300 301
Use case 6: Use Monday as week start
Code:
cal -m
Motivation: While calendars traditionally start the week on Sunday in some cultures, many international conventions and corporate work environments use Monday as the start of the week. This use case aligns the calendar display with these norms and can help in aligning personal or professional schedules with the work week.
Explanation:
The -m
option changes the start of the week from Sunday to Monday. This option modifies the traditional layout to fit different week-start conventions.
Example Output:
October 2023
Mo Tu We Th Fr Sa Su
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31
Use case 7: Number week numbers
Code:
cal -w
Motivation:
Week numbers are essential in numerous organizational and planning scenarios. Whether it’s for setting deadlines, organizing a timeline for a project, or syncing with systems that use week numbers, this feature of the cal
command is quite practical.
Explanation:
The -w
parameter adds week numbers to the calendar output. Note that this option is incompatible with the -j
option.
Example Output:
October 2023
October 2023
October 2023
October 2023
October 2023
October 2023
October 2023
October 2023
October 2023
October 2023
October 2023
October 2023
October 2023
October 2023
October 2023
October 2023
W40 1 2 3 4 5 6 7
W41 8 9 10 11 12 13 14
W42 15 16 17 18 19 20 21
W43 22 23 24 25 26 27 28
W44 29 30 31
Conclusion:
The cal
command is a simple yet powerful utility to display calendars directly within a command-line interface. Each use case highlights unique functionalities that cater to different organizational needs or personal preferences. Whether you’re planning for the future or just want to know what day of the week a date falls on, cal
serves as a quick and efficient tool.