Working with calendars in the shell


With calendar, which most distributions preinstall with the bsdmainutils package, you can output the current date's events in the terminal. If you set the command without further options, you will see a long list of mostly irrelevant information. You can restrict the query to the UK, for example, by calling calendar with the -f parameter and an appropriate event file, as shown in Figure 6. Such files can be found in /usr/share/calendar/en_UK/ on most distributions.

Figure 6: Restricting the query to UK events for a three-week period.

You can enter your own additional calendar data in your personal .calendar file. For example, on Debian and Ubuntu, copy the /usr/share/calendar/en_UK/calender.all file to $HOME/.calendar. Below the #include statements, enter your own anniversaries and events (in Listing 5, the entries for January 6 and 7). Each record begins with the month number, and you separate the following day with a slash. You use the tab key as a field separator between the date and the entry text.

Listing 5

Personal Calendar Entries

 * UK Calendar
#ifndef _en_UK_all_
#define _en_UK_all_
#include <en_UK/>
#include <en_UK/calendar.history>
#include <en_UK/calendar.christian>
#include <en_UK/calendar.literature>
#include <en_UK/>
#include <en_UK/>
01/06  Annivery of First ascent Blaabjerg north face
01/07  Birthday mother in law
#endif /* !_de_DE_all_ */

Taking a brief look at the calendar.christian file, you can see how calendar calculates the dependent holidays based on Easter Sunday. This function can be used to create your own calendars.

Table 2 contains some important options for using the program. You can save the call along with your preferred options as an alias in the shell's personal or system-wide configuration file.

Table 2

calendar Options



Specify the configuration file

-f <file>

Output the weekday


Number of days to show (future)

-l<number> 1

Number of days to show (past)


Show specific day


1 -l0 restricts output to today

Figure 7 shows some examples, where all commands refer to the user's personal calendar file. If you do not specify your personal file, Calendar resorts to the system-wide variant.

Figure 7: Examples with the user's personal calendar.all file.

Calendars with pcal

The pcal program [6], which can be found in the repositories of all the popular distributions, creates a calendar in PostScript or HTML format. Because of the extensive options and the granularity of the calendar data, working with it seems complicated at first. The tool's most important options are summarized in Table 3. The program's man page could certainly be a tad more user-friendly.

Table 3

pcal Options




Specify calendar config file

-f <file>


Select language

-a <country>


European date format


Paper format

-P <format>


Empties fields for days not in the month


First weekday

-F <number>

1 for Monday

Show moon phase daily


Show moon phases


Full moon, half moon, new moon



Helvetica, 12 point

Output file

-o <file>

Calendar month


Calendar year


Annual calendar on one page


Color black for specified day

-b <day>

Saturday (-b sat)

Deviating color

-g <day> -s <foreground>/<background>

Red on light beige for Sundays and holidays: 1.0:0.0:0.0/1.0:1.0:0.8

You store the configuration of the desired calendar in a separate file, named .pcal in our example. In the file, you define a calendar year with its holidays. Listing 6 shows an example for Germany with special regional holidays for Bavaria.

Listing 6

Personal .pcal file

01 # Week number on Monday
02 all Monday in all week %w
04 Easter # +/- is computed relative to Easter
05 # * by date = holiday
06 Monday after Easter* Easter Monday
07 Good_Friday* Good Friday
08 49th day after Easter* Whit Sunday
09 50th day after Easter* Whit Monday
10 39th day after Easter* Ascension Day
11 60th day after Easter* Corpus Christi
12 # none * = not a holiday
13 48th day before Easter Shrove Monday
14 46th day before Easter Ash Wednesday
15 7th day before Easter Palm Sunday
17 01. 01.* New Year
18 06. 01.* Epiphany
19 01. 05.* Labor Day
20 08. 08.* Peace Festival (Augsburg)
21 15. 08.* Assumption
22 03. 10.* German Unification Day
23 01. 11.* All Hallows
24 24. 12. Christmas Eve
25 25. 12.* 1st Day of Christmas
26 26. 12.* Boxing Day
27 31. 12. New Year's Eve
29 sun on_or_before 24. 12. 4th Sunday in Advent
30 sun on_or_before 17.12. 3rd Sunday in Advent
31 sun on_or_before 10.12. 2nd Sunday in Advent
32 sun on_or_before 3.12. 1st Sunday in Advent

Some special rules apply here. There are different specifications for the specific day. With all <day>, you designate a day for which you want special highlighting. Listing 6, line 1, displays the word "Week" and the consecutive week number every Monday. Line 17 shows New Year's Day as a public holiday. There must be a space between the day and month entries.

To display a day as a public holiday, add an asterisk (*) followed by the desired text. Many holidays are a fixed number of days before or after Easter (see Listing 6, lines 4-15). Other holidays work like New Year's Day: You specify the holiday with a fixed date, including an asterisk if it's a public holiday.

Christmas can be complicated because December 24 can also be the fourth Sunday in Advent (e.g., in 2023). You need to use on_or_before here. This allows December 24 to be the fourth Sunday in Advent if it happens to be on a Sunday. You can then define the dates of the remaining Sundays in Advent (see lines 29-32 of Listing 6).

Nonstandard characters can cause problems here. Modern distributions use UTF-8 encoding, but pcal insists on ISO-8859-15.

By default, pcal outputs Sundays and holidays in gray, which usually makes these days more prominent in black and white prints. You can create an overview calendar with Sundays and holidays printed in red and the moon phases, using the code in Listing 7. Figure 8 shows the results.

Listing 7

Annual Calendar

$ pcal -f .pcal -a en -E -P a4 \
 -B -F 0 -M -g sun \
 -s 1.0:0.0:0.0/1.0:1.0:0.8 \
 -b sat -n Helvetica/10 -w \
 -o 2021
Figure 8: An annual calendar created with pcal.

You can create a monthly calendar without the -w option; instead, you specify the month before the year (Listing 8). The result is shown in Figure 9. You can process the resulting PostScript file to create a complete calendar page by adding a photo, for example, using Inkscape.

Listing 8

Monthly Calendar

$ pcal -f .pcal -a en -E -P a4 \
 -B -F 0 -M -g sun \
 -s 1.0:0.0:0.0/1.0:1.0:0.8 \
 -b sat -n Helvetica/10 \
 -o 01 2021
Figure 9: A monthly calendar created using pcal.

Appointment Management

A small but good command-line program named calcurse, which you will find in the repositories of all the popular distributions, lets you manage general tasks and tasks with deadlines. The simple interface is more or less self-explanatory. If you have worked with Nano before, you will get along with the menu control used in calcurse right away. You can jump between the Appointments, Calendar, and To do fields by pressing the tab key; you use the arrow keys to reach targets in your appointments and calendar. Figure 10 shows the full screen.

Figure 10: With calcurse, you can manage tasks and deadlines.

To enter a new appointment, press A and enter the start time, the end time, and the description text (Figure 11). Pressing Enter saves the new appointment (Figure 12). Press Ctrl+T to create a new task (Figure 13). Start by entering the task text, then press Enter, and then set a priority. This affects the order in which tasks are displayed. Figure 14 shows the appointment and task entries.

Figure 11: In calcurse, enter an appointment's start time (top), end time (middle), and a description text (bottom).
Figure 12: The complete appointment in calcurse.
Figure 13: In calcurse, you enter tasks (top) and set a priority for them (bottom).
Figure 14: Appointment and task entries in calcurse.

Pressing O takes you to more commands and the settings. You can export the calendar entries in the ICAL or PCAL format or import data in these formats. If you call calcurse with the -a option, it displays all appointments for the current date on-screen (Figure 15).

Figure 15: An appointment query for the current date.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Command Line: Calendar Tools

    We take a spin through several personal calendar apps that you can manage from the command line.

  • Command Line: cal and date

    The legacy cal and date tools help users keep track of the time and date. You can even change the system time with a single shell command.

  • Mozilla Lightning

    The Lightning add-on lets users upgrade their Mozilla Thunderbird email client and turn it into a convenient, versatile groupware product.

  • Calcurse

    Calcurse combines a calendar with appointments management and a task list, so you can use a terminal to keep track of the day's events at a glance.

  • Mozilla Sunbird

    Mozilla Sunbird may be just what you need to help you manage your appointments and tasks on Linux.

comments powered by Disqus

Direct Download

Read full article as PDF:

Price $2.95

Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Find SysAdmin Jobs