Linux cal and ncal Commands to Display Calender

Beside date command, Linux also has cal command to display calendar. As its name, cal just show you the calendar in many ways.

There is also ncal command which has same function with cal. Let’s start.

1) Run cal

Cal is a built-in command which shipped in every Linux distribution. To run cal, just type cal on your console.

$ cal
Default view of calendar

2) Display calender in full year view

To display it in full year view, put the year you want to view after cal command or use -y year parameter. Let say you want to view 2013 calendar.

$ cal 2013


$ cal -y 2013
Full year calendar

3) Show specific month

To fulfill this, we can use -m month_name parameter. Here’s a sample :

$ cal -m Feb
Month view of calendar

As you can see, you can type in the full name of the month or simply abbreviated course.

4) Print Julian days

Julian days is days one-based which numbered from January 1. To print calender in this format, use -j parameter.

$ cal -j
Julian calendar

On Julian calender, we see that December 7, 2013 is converted into day 341 in 2013 year.

5) Display 3 months calender

You can display calender in 3 month format. One for previous, current and next month. Use -3 parameter to do it.

$ cal -3
3 months calendar

6) Display the number of month after the current month

If you need to do it, use -A number parameter.

$ cal -A 2
2 months after calendar

7) Display the number of month before the current month

If you need to do it, use -B number parameter.

$ cal -B 2
2 months before calendar

8) Print week numbers

To show a week number, we can not use cal command. This time, we use ncal command.

$ ncal -w
Weekly view

Ncal print a portrait view. The week numbers are printed on the bottom of each months.

9) Weeks start on Monday

By default, weeks start on Sunday. If you want to start on Monday, you can use -M parameter. Once again, this parameter is applied to ncal command only.

$ ncal -M
Start on Monday

10) Display country codes

To print country codes in calendar, we can use -p parameter. This parameter also only applied to ncal command.

$ ncal -p
Country codes

The difference between cal and ncal are the view orientation and the parameters of each other. For example, -w parameter to print week numbers, can not be used in cal command. You will get an error message like :

Usage :
cal [general options] [-hjy] [[month] year]
cal [general options] [-hj] [-m month] [year]
ncal [general options] [-bhJjpwySM] [-s country_code] [[month] year]
ncal [general options] [-bhJeoSM] [year]
General options : [-NC3] [-A months] [-B months]
For debug the highlighting: [-H yyyy-mm-dd] [-d yyyy-mm]

But they producing the same function that giving us the information about calendar.

Leave a Comment