Introduction
In this lab, you will learn how to use the cal command in Linux to display calendars for the current month, a specific month, or a full year. The cal command is a useful tool for system monitoring and management, as it allows you to quickly reference calendar information without the need for a graphical interface.
You will start by understanding the purpose and syntax of the cal command, including how to display the calendar for the current month, a specific month and year, or a full year. Then, you will practice using the cal command to display the calendar for the current month, as well as calendars for specific months and years.
Understand the Purpose and Syntax of the cal Command
In this step, you will learn about the purpose and syntax of the cal command in Linux. The cal command is used to display a calendar for the current month, a specific month, or a specific year.
To display the calendar for the current month, simply run the cal command:
cal
Example output:
September 2022
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
To display the calendar for a specific month and year, use the following syntax:
cal [month] [year]
For example, to display the calendar for April 2023:
cal 4 2023
Example output:
April 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
The cal command can also display the calendar for a full year by specifying only the year:
cal [year]
For example, to display the calendar for the year 2024:
cal 2024
Example output:
2024
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 1 2 3 1 2
7 8 9 10 11 12 13 4 5 6 7 8 9 10 3 4 5 6 7 8 9
14 15 16 17 18 19 20 11 12 13 14 15 16 17 10 11 12 13 14 15 16
21 22 23 24 25 26 27 18 19 20 21 22 23 24 17 18 19 20 21 22 23
28 29 30 31 25 26 27 28 29 24 25 26 27 28 29 30
31
This displays the calendar for the entire year, with each month shown in a separate column.
Display the Current Month's Calendar
In this step, you will learn how to use the cal command to display the calendar for the current month.
To display the calendar for the current month, simply run the cal command:
cal
Example output:
September 2022
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
The cal command without any arguments will display the calendar for the current month and year.
Display the Calendar for a Specific Year or Month
In this step, you will learn how to use the cal command to display the calendar for a specific year or month.
To display the calendar for a specific month and year, use the following syntax:
cal [month] [year]
For example, to display the calendar for April 2023:
cal 4 2023
Example output:
April 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
The cal command can also display the calendar for a full year by specifying only the year:
cal [year]
For example, to display the calendar for the year 2024:
cal 2024
Example output:
2024
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 1 2 3 1 2
7 8 9 10 11 12 13 4 5 6 7 8 9 10 3 4 5 6 7 8 9
14 15 16 17 18 19 20 11 12 13 14 15 16 17 10 11 12 13 14 15 16
21 22 23 24 25 26 27 18 19 20 21 22 23 24 17 18 19 20 21 22 23
28 29 30 31 25 26 27 28 29 24 25 26 27 28 29 30
31
This displays the calendar for the entire year, with each month shown in a separate column.
Summary
In this lab, you learned about the purpose and syntax of the cal command in Linux. The cal command is used to display a calendar for the current month, a specific month, or a specific year. You can display the calendar for the current month by simply running the cal command. To display the calendar for a specific month and year, you can use the syntax cal [month] [year]. The cal command can also display the calendar for a full year by specifying only the year.



