FUNDAMENTALS A Complete Guide for Beginners
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]...
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.
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.
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 “-h” option 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.
Similar Readings
- The “man” Command in Linux [6 Practical Examples]
- The “history” Command in Linux [6 Practical Examples]
- The “cal” Command in Linux [7 Practical Examples]
- The “bc” Command in Linux [10+ Practical Examples]
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.
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.
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.
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.
Similar Readings
- The “cron” Command in Linux [3 Practical Examples]
- The “crontab” Command in Linux [10 Practical Examples]
- The “date” Command in Linux [8+ Practical Examples]
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.
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.
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
- The “neofetch” Command in Linux [12+ Practical Examples]
- The “tree” Command in Linux [14 Practical Examples]
- The “whatis” Command in Linux [12 Practical Examples]
- The “whereis” Command in Linux [10 Practical Examples]
- The “which” Command in Linux [3 Practical Examples]
- The “at” Command in Linux [7 Practical Examples]
- The “tee” Command in Linux [4 Practical Examples]