Author: Joe Barr
One of the things computers do best is remember stuff. Dates. Appointments. Holidays. Birthdays. All sorts of stuff. There is a wealth of date-related information available to you at the CLI. This week we’ll take a look at two handy date-related tools available in the CLI: cal and calendar.
cal tech
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:
March 2004 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
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 2004
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 2004
That lists month 2, with the days a little more obviously being day of the year rather than day of the month, as you can see below:
February 2004
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
60
If you liked that, add a -y and cal will print the entire year for you. If you specify only a “-y” as an argument, cal will print a normal calendar for the entire year.
calendar daze
There is a similar tool called “calendar” which lists the items it finds in various calendar files for the current and the following day. It comes with a number of different calendars. I found calendars for the following topics listed in /usr/share/calendar on my LibraNet installation: history, US holiday, Australia, holiday, world, birthday, Christian, computer, Judaic, Croatian, music, Discordian, FreeBSD, German, New Zealand, Pagan, and Russia. I may have missed a couple, but you get the idea. There are a lot of them. Too many, as a matter of fact. But you can fix that.
To whittle the list of calendars down to a more reasonable size, copy calendar.all from /usr/share/calendar to /etc/calendar. You can do that with these commands:
su
cp /usr/share/calendar/calendar.all /etc/calendar
Then open the calendar.all in /etc/calendar with your favorite text editor and simply remove all the lines which begin “include <calendar.whatever>” when “whatever” is not wanted. After a bit of tailoring to my calendar.all, entering calendar
at the command line resulted in this:
18 Mar* Aleksei Leonov performs first spacewalk, 1965
18 Mar* Destruction of the Ring (LOTR)
19 Mar* Swallows return to Capistrano
19 Mar* St. Joseph's Day, obeserved in Colombia, Costa Rica, Holy See,
Liechtenstein, San Marino, Spain, Venezuela
19 Mar* Tree Planting Day in Lestho
19 Mar* 1st Quarter Day - Spring (Vernal) Equinox
19 Mar* Mojoday (5th of the Season of Discord) Festival of Dr. Van Van Mojo
That’s pretty neat, but then I discovered something even neater. I could make my own calendar.file and include it in calendar.all. That way I can get reminders about birthdays and anniversaries for friends and family instead of only for dead presidents and rock and roll stars. Here’s how I created my personal calendar file.
I began by copying calendar.music to a new file called calendar.personal. I did this as root in the /usr/share/calendar directory by entering:
cp calendar.music calendar.personal
Next, I removed all the comment lines and #include lines from the file, so that only the following lines remained:
#ifndef _calendar_music_
#define _calendar_music_
#endif /* !_calendar_music_ */
Next, I replaced the word “music” with “personal” everywhere it appeared in the file, so it looked like this:
#ifndef _calendar_personal_
#define _calendar_personal_
#endif /* !_calendar_personal_ */
Then I began adding personal dates, using the following format, on lines I added to calendar.personal between the #define line and the #endif line:
Mmm dd <tab> Event description
For example:
Mar 18 <tab> Aunt Nadine’s birthday
Mar 19 <tab> Cujo’s rabies shot due
Mar 20 <tab> Last Sunday before Mar 21
Be sure to put a tab between the date and the description, or it won’t be displayed. When you’re done, save your personal calendar file and open /etc/calendar/calendar.all in your editor. You’ll need to be doing all of this as root, by the way. In calendar.all, add the following line where you see the other #include lines:
#include <calendar.personal>
Then save that. You’re all done. Just type (as a regular user) “calendar” on the command line and see what you get.
OK, that’s it for this week. According to my personal calendar, it’s time to put this one to rest.