cal & ncal – Linux Commands To Display Calendar Information

By | 18/07/2013

Linux provides ncal and cal utilities which can be used to display calendar on command line. Once you get used to them, you’ll realize that things are faster with these utilities as compared to manually looking for calendars in GUI. Both of these utilities, when combined, provide a rich set of options through which you can display calendar in almost any way. In this article, I will explain how to use these utilities to display calendar on Linux command line.

NOTE –  All these examples are tested on Ubuntu Linux.

 

Linux calendar – ncal and cal examples

Q1. How to display information related to current month?
Ans. Use cal utility without any option. Here is an example :

$ cal
     July 2013        
Su Mo Tu We Th Fr Sa  
    1  2  3  4  5  6  
 7  8  9 10 11 12 13  
14 15 16 17 18 19 20  
21 22 23 24 25 26 27  
28 29 30 31

You can also use ncal utility for the same :

$ ncal
    July 2013         
Su     7 14 21 28   
Mo  1  8 15 22 29   
Tu  2  9 16 23 30   
We  3 10 <strong>17</strong> 24 31   
Th  4 11 18 25      
Fr  5 12 19 26      
Sa  6 13 20 27

You can see that complete month was displayed with highlighted current date. If you want, highlighting can be turned off using -h option with cal utility.

NOTE – You can use -H and -d options (see man page for more info) for debugging date selection and current date highlighting.

Q2. How to display Julian calendar?
Ans. For Julian calendar, use ncal utility with -J option.

Here is an example :

$ ncal -J
    July 2013         
Su  1  8 15 22 29   
Mo  2  9 16 23 30   
Tu  3 10 17 24 31   
We  4 11 18 25      
Th  5 12 19 26      
Fr  6 13 20 27      
Sa  7 14 21 28

Q3. How to display date of Easter?
Ans. For Easter date, use ncal utility with -e option.

Here is an example :

$ ncal -e
31 March 2013

Q4. How to display Julian days?
Ans. For Julian days (one-based and numbered from January 1), use -j option with cal utility.

Here is an example :

$ cal -j
         July 2013           
 Su  Mo  Tu  We  Th  Fr  Sa  
    182 183 184 185 186 187  
188 189 190 191 192 193 194  
195 196 197 198 199 200 201  
202 203 204 205 206 207 208  
209 210 211 212

Q5. How to display a specified month (ie a month different from current month)?
Ans. For this, use -m option followed by a decimal number representing month.

Here is an example :

$ cal -m1
    January 2013      
Su Mo Tu We Th Fr Sa  
       1  2  3  4  5  
 6  7  8  9 10 11 12  
13 14 15 16 17 18 19  
20 21 22 23 24 25 26  
27 28 29 30 31

You can see that by default year is assumed as current year. If if is desired to get month of some other year, just pass that year while running the command above.

Here is an example :

$ cal -m1 1999
    January 1999      
Su Mo Tu We Th Fr Sa  
                1  2  
 3  4  5  6  7  8  9  
10 11 12 13 14 15 16  
17 18 19 20 21 22 23  
24 25 26 27 28 29 30  
31

So you can see that first month of year 1999 was displayed.

Q6. How to display previous, requested and next month?
Ans. This can be achieved by using -3 option.

Here is an example :

$ cal -3
     June 2013             July 2013            August 2013       
Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa  
                   1      1  2  3  4  5  6               1  2  3  
 2  3  4  5  6  7  8   7  8  9 10 11 12 13   4  5  6  7  8  9 10  
 9 10 11 12 13 14 15  14 15 16 17 18 19 20  11 12 13 14 15 16 17  
16 17 18 19 20 21 22  21 22 23 24 25 26 27  18 19 20 21 22 23 24  
23 24 25 26 27 28 29  28 29 30 31           25 26 27 28 29 30 31  
30

So you can see that previous, current and next months were displayed in order.

Similarly, you can use the same method to display previous and next months corresponding to any month of any year.

Here is an example of this :

$ cal -3 -m3 1984
   February 1984           March 1984            April 1984       
Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa  
          1  2  3  4               1  2  3   1  2  3  4  5  6  7  
 5  6  7  8  9 10 11   4  5  6  7  8  9 10   8  9 10 11 12 13 14  
12 13 14 15 16 17 18  11 12 13 14 15 16 17  15 16 17 18 19 20 21  
19 20 21 22 23 24 25  18 19 20 21 22 23 24  22 23 24 25 26 27 28  
26 27 28 29           25 26 27 28 29 30 31  29 30

Q7. How to display date of orthodox Easter?
Ans. This can be done using ncal utility with -o option.

Here is an example :

$ ncal -o
 5 May 2013

Q8. How to display country codes?
Ans. For country codes, execute ncal utility with -p option.

Here is an example :

$ ncal -p
 AL Albania        1912-11-30      IT Italy          1582-10-04
 AT Austria        1583-10-05      JP Japan          1918-12-18
 AU Australia      1752-09-02      LI Lithuania      1918-02-01
 BE Belgium        1582-12-14      LN Latin          9999-05-31
 BG Bulgaria       1916-03-18      LU Luxembourg     1582-12-14
 CA Canada         1752-09-02      LV Latvia         1918-02-01
 CH Switzerland    1655-02-28      NL Netherlands    1582-12-14
 CN China          1911-12-18      NO Norway         1700-02-18
 CZ Czech Republic 1584-01-06      PL Poland         1582-10-04
 DE Germany        1700-02-18      PT Portugal       1582-10-04
 DK Denmark        1700-02-18      RO Romania        1919-03-31
 ES Spain          1582-10-04      RU Russia         1918-01-31
 FI Finland        1753-02-17      SI Slovenia       1919-03-04
 FR France         1582-12-09      SW Sweden         1753-02-17
 GB United Kingdom 1752-09-02      TR Turkey         1926-12-18
 GR Greece         1924-03-09     *US United States  1752-09-02
 HU Hungary        1587-10-21      YU Yugoslavia     1919-03-04
 IS Iceland        1700-11-16

Q9. How to display week numbers?
Ans. You can get week numbers for the weeks in current month by using -w option with ncal utility.

Here is an example :

$ ncal -w
    July 2013         
Su     7 14 21 28   
Mo  1  8 15 22 29   
Tu  2  9 16 23 30   
We  3 10 17 24 31   
Th  4 11 18 25      
Fr  5 12 19 26      
Sa  6 13 20 27      
   26 27 28 29 30

Observe that the week numbers are listed in the last row.

Q10. How to display complete calendar for a year?
Ans. This can be done using ncal utility with option -y.

Here is an example :

$ ncal -y 2010
                                  2010
    January           February          March             April             
Su     3 10 17 24 31     7 14 21 28        7 14 21 28        4 11 18 25   
Mo     4 11 18 25     1  8 15 22        1  8 15 22 29        5 12 19 26   
Tu     5 12 19 26     2  9 16 23        2  9 16 23 30        6 13 20 27   
We     6 13 20 27     3 10 17 24        3 10 17 24 31        7 14 21 28   
Th     7 14 21 28     4 11 18 25        4 11 18 25        1  8 15 22 29   
Fr  1  8 15 22 29     5 12 19 26        5 12 19 26        2  9 16 23 30   
Sa  2  9 16 23 30     6 13 20 27        6 13 20 27        3 10 17 24      

    May               June              July              August            
Su     2  9 16 23 30     6 13 20 27        4 11 18 25     1  8 15 22 29   
Mo     3 10 17 24 31     7 14 21 28        5 12 19 26     2  9 16 23 30   
Tu     4 11 18 25     1  8 15 22 29        6 13 20 27     3 10 17 24 31   
We     5 12 19 26     2  9 16 23 30        7 14 21 28     4 11 18 25      
Th     6 13 20 27     3 10 17 24        1  8 15 22 29     5 12 19 26      
Fr     7 14 21 28     4 11 18 25        2  9 16 23 30     6 13 20 27      
Sa  1  8 15 22 29     5 12 19 26        3 10 17 24 31     7 14 21 28      

    September         October           November          December          
Su     5 12 19 26        3 10 17 24 31     7 14 21 28        5 12 19 26   
Mo     6 13 20 27        4 11 18 25     1  8 15 22 29        6 13 20 27   
Tu     7 14 21 28        5 12 19 26     2  9 16 23 30        7 14 21 28   
We  1  8 15 22 29        6 13 20 27     3 10 17 24        1  8 15 22 29   
Th  2  9 16 23 30        7 14 21 28     4 11 18 25        2  9 16 23 30   
Fr  3 10 17 24        1  8 15 22 29     5 12 19 26        3 10 17 24 31   
Sa  4 11 18 25        2  9 16 23 30     6 13 20 27        4 11 18 25

So we see that complete calendar for year 2010 was displayed in output.

[READ MORE ON NEXT PAGE]

Leave a Reply

Your email address will not be published. Required fields are marked *