The “ncal” Command in Linux [8 Practical Examples]

The ncal command in Linux is a useful tool to view the calendar in the Linux Terminal. This command can be a part of daily life as everyone needs the calendar one way or another. There is another tool available to view the calendar which is the cal command. However, in the cal command, the current date isn’t highlighted and nowadays in most systems, it is just a symbolic link of the ncal command in Linux. In this article, I will show you the usage of different options of the ncal command in Linux with practical examples.

A. Description

The ncal command in Linux is a Unix-based tool to view calendars. However, it doesn’t come by default in most systems and may require to install manually. It is the successor of cal command. It provides advanced formatting compared to the cal command. In addition to that, it has some extra features like showing holidays, the lunar calendar etc. Moreover, it has a lot of options to customize your output according to someone’s needs.

B. Syntax

The syntax of the ncal command in Linux is simple in looking at. The syntax is cal followed by one or multiple options and arguments.

cal [OPTION]... [ARGUMENT]...
Note: In the above syntax, OPTION and ARGUMENT  enclosed by square brackets followed by 3 dots represents that multiple options and arguments can be used at the same time

C. Options

As I have mentioned earlier, the ncal command comes with a lot of options. To know about them all, execute the following command:

man ncal

Now I will list some of the useful options of the ncal command in Linux for you in the following:

Useful Options

  • -h, remove highlight on the current date.
  • -y, is used to view the calendar of a specific year.
  • -m, shows the calendar of a specific month of the current year.
  • -3, prints the calendar of previous, current and following months.
  • -w, shows the week number.
  • -B, displays a specific number of months before the current month.
  • -A, prints a specific number of months after the current month.
Note: The options in Linux CLI (Command Line Interface) are all case-sensitive, so use them carefully

Practical Examples of the “ncal” Command in Linux

In this section, I will show some primary usage of the ncal command in Linux. You should follow every step with me. For your information, the year is 2023 while I am writing this article and today’s date is the 2nd of February.

Example 1: Calendar of Current Month Using the “ncal” Command in Linux

In the beginning, I will show how to view the calendar of the current month using the ncal command in Linux. Follow the steps below to print the current month:

Steps to Follow >

➊ At first open the Ubuntu Terminal.

➋ Write the following command in the command prompt:

ncal

➌ Now, press the ENTER button.

Output >

The output is showing the calendar of the month of February of the year 2023 which happens to be the current month. The left column shows the name of the days, followed by dates. In addition, notice that the current date is highlighted.Calendar of current month using the ncal command in Linux

Example 2: Remove the Highlight of the Current Date

In the previous example, you have seen that the current date is highlighted. What if you want to turn off the highlighting? You need to use the “-hoption for that. Now do the following to turn off highlighting:

Steps to Follow >

➊ Launch a Terminal in your Ubuntu.

➋ Copy the following command in the Terminal:

ncal -h

➌ Hit the ENTER button from the keyboard.

Output >

The output is similar to Example 1, except the current date isn’t highlighted here.calendar with the highlighter turned off


Similar Readings


Example 3: Calendar of a Specific Year Using the “ncal” Command in Linux

The ncal in Linux is capable to show any calendar based on year. For instance, I want to print the calendar of the year 1971. I need to use the option-y” followed by the year number as the value of that option. Now do the following with me:

Steps to Follow >

➊ Firstly, go to your Ubuntu and open a Terminal.

➋ Insert the command below in the command prompt:

ncal -y 1971

➌ Press the ENTER key from your keyboard.

Output >

The output is displaying the whole calendar of the year 1971. Even though I haven’t shown the full image, you have gotten the idea.Calendar of a specific year using the ncal command in Linux

Example 4: Calendar of Specific Month of Current Year

Sometimes, you may require to view the calendar of the month of the running year. The ncal command in Linux provides an option for that which is option -m”. You need to write the month number as the value of that option. As I want to view the calendar of month December, I will type 12. Now follow the steps below to view the calendar of a month of the current year:

Steps to Follow >

➊ Launch an Ubuntu Terminal.

➋ Copy the following command in the Terminal:

ncal -m12

OR,

ncal -m 12

➌ Find the ENTER button on your keyboard and hit it.

Output >

Now I am seeing the calendar for the month of December.Calendar of a specific month of current year

Example 5: Calendar of Previous, Current and Next Months Using the “ncal” Command in Linux

In this example, you will learn how to see the calendar of the previous, current and upcoming months at once by using a single option. I will use option-3” of the ncal command in Linux for this purpose. As I am currently in the month of February, I expect to see the months of January and March in the Terminal. Now do the following with me to display the past, present and future months:

Steps to Follow >

➊ Go to your Ubuntu and launch a Terminal.

➋ Insert the command below in the Terminal:

ncal -3

➌ Hit the ENTER button from the keyboard.

Output >

As expected, the output is showing the month before February which is January and after February which is March.Calendar of past , present, future months using the ncal command in Linux

Example 6: Week Number Below Every Week the Calendar

Now I will combine two options in the ncal command in Linux. The first option -w” shows the number of weeks at the bottom of the calendar of a month. And the second option is the option-m” which displays the calendar of a specific month of the current year and I have worked with it in Example 4. Now follow the steps below to show the week numbers:

Steps to Follow >

➊ Open a Terminal in Ubuntu.

➋ Write the following command in the command prompt:

ncal -w -m12

OR,

ncal -w -m 12

➌ Now press the ENTER button from the keyboard.

Output >

It is common knowledge that there are 52 months in a year. I am seeing the calendar for the month of December and last week’s number is 52. So it all checks out.Calendar with week numbers


Similar Readings


Example 7: Show a Specific Number of Months After the Current Month Using the “ncal” Command in Linux

In this example, I will view a specific number of months before the current month. The option -B” of the ncal command in Linux is used for this purpose. I want to view two months before my current month which is February, so I will put the number “2” followed by option-B”. Do the following to display two months before your current month:

Steps to Follow >

➊ At first, launch an Ubuntu Terminal.

➋ Insert the following command in the Terminal:

ncal -B2

OR,

ncal -B 2

➌ Then hit ENTER from your keyboard.

Output >

I am in the month of February of the year 2023. In the output. it is the showing for the month of January 2023 and December of the year 2022.Calendar of two months before current month using the ncal command in Linux

Example 8: Show a Specific Number of Months After the Current Month

Finally, I will end my examples by showing how to print a specific number of months after the current month using the ncal command in Linux. I will use the option -A” for that. Let’s say I want to see the calendar for the next two months. I will provide the number “2” as the value of option-A” for that case. Now do the following to display two months after the current month:

Steps to Follow >

➊ Go to your Ubuntu and open a Terminal.

➋ Type the following command in the Terminal:

ncal -A2

➌ Now press the ENTER key from your keyboard.

Output >

The Terminal is printing the calendar for the month of March and April as they come after the month of February, once again which is my current month.calendar of two months after the current month

Conclusion

The ncal command in Linux is an easy and useful tool and it is not that hard to learn. Practice all the examples here. If you want more, go to the manual page of the ncal command and try the options there as well. Hopefully, the ncal command in Linux has become a part of your day-to-day life now.


Similar Readings

Rate this post
LINUX
FUNDAMENTALS
A Complete Guide for Beginners Enroll Course Now
Walid Al Asad

Hello Everyone! I am Walid Al Asad. Currently, I am working at a tech company named Softeko as a Linux Content Developer Executive. I live in Dhaka, Bangladesh. I have completed my BSc. in Mechanical Engineering from Bangladesh University of Engineering and Technology (BUET). You can find me on LinkedIn, and ResearchGate. Read Full Bio

Leave a Comment