10 Practical Examples of Linux Cal/NCal command for Beginners

Linux ncal command output

10 Practical Examples of Linux Cal/NCal command for Beginners

If you want to quickly view a calendar on the terminal in Linux, then cal is the command-line tool that you should be using. By default, the command displays the current month in output.

Linux cla command output

There’s another similar utility, dubbed ncal. It differs from cal in the sense that it offers an alternative layout, more options, and the date of Easter.

Linux ncal command output

In this article, we will discuss both these tools in detail, giving you an idea about their capabilities and feature-set.

1. How to turn off highlighting of today’s date?

As you can see in the default output above, the current date is highlighted in white. However, if you want, you can turn off this highlighting. This can be done using the -h command-line option:

cal not highlight day

2. How to display a calendar for a specific month or complete year?

While the cal/ncal commands display the current month by default, you can use the -m command-line option in order to have a specific month displayed. This option requires a numeric value (1-12) that represents the month you want the command to display. 

For example, the following command will display the month of January 2017:

cal -m1

cal calendar show specific month

Similarly, the calendar for a complete year can be displayed using the -y command-line option.

cal -y [year]

cal command show all months of a year

3. How to print the week number below each week column?

To print the week number below each week column, use the -w command-line option. The following screenshot shows how week numbers are displayed (the last highlighted row):

cal show week number

4. How to display previous, current and next month in one go?

The cal/ncal commands also display the previous, current and next month surrounding today. For this, you need to pass the -3 command-line option.

cal show previous and next month

5. How to add a specified number of months before or after the current one in output?

If you want, you can make the cal/ncal display a specific number of months after the current month. This can be done using the -A command-line option which requires the number of additional months you want to display.

For example, the following screenshot shows how you can display 2 months (after the current month) in the output:

show x months before or after month

Similarly, in case you want to display a specific number of months preceding the current month, use the -B command-line option.

cal -B command option

Both of these options can also be used together. For example, if you want to display a calendar for November 2016 to June 2017, following is the command you need to run:

cal -B4 -A3

cal before and after month

6. How to run cal in ncal mode and vice-versa?

While both cal and ncal have separate output layouts, you can actually force them to switch to the other’s layout. To make cal switch to ncal’s layout, use the -N command-line option. Similarly, the -C option forces ncal to switch to cal’s output mode.

run cal in ncal mode

Note: The -b option for ncal also does the same (the man page says use this option when you want to have old style format for ncal output).

7. How to change the start day of the week?

Both cal and ncal assume Sunday as the first day of the week. This is by default. However, if you want, you can change this, and have weeks begin with Monday instead. This can be done using the -M option (works only for ncal though).

change start day of week

8. How to display a particular month and year?

Suppose you want the cal/ncal commands to display a month/year other than the current month/year. This you can do by using the -d command-line option. This option requires a year and month to passed in yyyy-mm format.

For example, to display March of 2016, use the following command:

cal -d 2016-03

display a particular month

9. How to display the date of Easter?

The -o and -e command-line options are what you need here. While the former tells the ncal command to display the date of Orthodox Easter (for Greek and Russian Orthodox Churches), the latter asks ncal to display date of Easter for western churches.

cal show easter date

10. How to display Julian calendar and Julian days?

To display Julian calendar using ncal, use the -J command-line option.

cal show julian calendar

And for Julian days, use -j command-line option (supported by both cal and ncal):

cal show julian calendar days


Both cal and ncal are pretty useful if your work involves using calendars on the command line. The ncal command is slightly better than cal when it comes to features (or command-line options). Do try out all the examples mentioned here, and when in doubt, refer to the commands’ man page. The commands in this tutorial have been tested on Ubuntu and Debian Linux, but they will work in the same way on other distributions like CentOS too.

Đăng ký liền tay Nhận Ngay Bài Mới

Subscribe ngay

Cám ơn bạn đã đăng ký !

Lỗi đăng ký !

Add Comment

Click here to post a comment

Đăng ký liền tay
Nhận Ngay Bài Mới

Subscribe ngay

Cám ơn bạn đã đăng ký !

Lỗi đăng ký !