The wonderful cal command can tell you a lot. Entered without any arguments, it shows you a calendar for the current month that looks like this:
$ cal April 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
But there are several arguments you can add to the cal command to tell you even more. The Julian date, for example. Try this:
$ cal -j 1 2022
The example above produces a rather normal looking calendar, but the -j argument changes it from showing the day of the month (1-31 for January) to the Julian date, or day of the year, instead.
Of course for January, it’s hard to tell the difference. Try this:
$ cal -j 2 2022 February 2022 Su Mo Tu We Th Fr Sa 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
If you encounter the below error while running the cal command:
cal: command not found
you may try installing the below package as per your choice of distribution:
Distribution | Command |
---|---|
OS X | brew install util-linux |
Debian | apt-get install bsdmainutils |
Ubuntu | apt-get install bsdmainutils |
Alpine | apk add util-linux |
Arch Linux | pacman -S util-linux |
Kali Linux | apt-get install bsdmainutils |
CentOS | yum install util-linux |
Fedora | dnf install util-linux |
Raspbian | apt-get install bsdmainutils |
cal Command Examples
1. To display the calender for 2011:
# cal 2011
2. To display single month output:
# cal -1
3. To display previous/current/next month output:
# cal -3
4. To display Sunday as a first day:
# cal -s
5. To display monday as a first day of the output:
# cal -m
6. To display the Julian dates:
# cal -j
7. To display the calender of current year:
# cal -y
8. To display the version information:
# cal -V
Final Thoughts
The cal command writes a Gregorian calendar to standard output. If you specify a four-digit year operand, a calendar for that year is written. If you specify no operands, a calendar for the current month is written. You can display a calendar for any month of any year by specifying the month, as a digit from 1 to 12, followed by any four-digit year up to 9999.