Linux cal command
What is the cal command
calIt is a simple but practical command-line tool in Linux systems, used to display calendars in the terminal. Its name comes from the abbreviation of "calendar".
Basic functions
- Display the calendar of the current month
- Display the calendar of a specified month
- Display the calendar for an entire year
- Support multiple display formats and options
Basic syntax
cal [选项] [[月份] 年份]
Parameter description
- Without any parameters: displays the calendar of the current month
- Specifying only the year: displays calendars of all months of that year
- Specifying both month and year: displays the calendar of that month
Common options explained in detail
1. Display current month calendar (default)
Example
Example output:
十月 2023 日 一 二 三 四 五 六 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
2. Display calendar of specified month
Example
Display the calendar of December 2023
3. Display calendar for entire year
Example
Display calendars of all months of 2023
4. Display previous/next month calendar
Example
Display the current month and the months before and after it (three months in total)
5. Display Julian calendar (1-366)
Example
Display calendar in Julian date format, counting from day 1 to day 365/366 each year
6. Display Monday as the first day of the week
Example
By default Sunday is the first day of the week; use-moption to change to Monday
Advanced usage
1. Combine options
Example
Display the Julian calendar of December 2023, with Monday as the first day of the week
2. Display calendar for a specific year
Example
Display the calendar of 1752 (the year of the historical transition from the Julian calendar to the Gregorian calendar)
3. Display historical calendar
Example
Display the calendar of September 1752 (note that this month is missing 11 days)
Practical application examples
Example 1: Quickly view next month
Example
Example 2: View current quarter
Example
cal -3 $(( (month-1)/3*3+1 )) $(date +%Y)
Example 3: Create calendar file
Example
Save the 2023 calendar to a file
FAQ
Q1: cal command display inaccurate?
A: Make sure the entered year is in the range 1-9999 and the month is in the range 1-12
Q2: How to display calendar in other languages?
A: You can set the LANG environment variable, for example:
Example
Q3: What is the difference between cal and ncal?
A: ncal is a variant of cal, providing different layout options. You canman ncalview details
Summary table
| Option | Description | Example |
|---|---|---|
| None | Display current month calendar | cal |
| -j | Julian calendar format | cal -j |
| -m | Monday as the first day of the week | cal -m |
| -3 | Display previous/current/next three months | cal -3 |
| -y | Display all months of the current year | cal -y |
| Month Year | Display calendar of specified month | cal 12 2023 |
| Year | Display calendar of specified year | cal 2023 |
Linux command encyclopedia