Commands for displaying calendar information in Linux: cal and ncal

Source: Internet
Author: User

In Linux, there are two built-in commands cal and ncal used to display and calibrate the calendar. Once you are used to using them, you will find that using commands is much faster and more convenient than using the mouse in the GUI calendar. There are many parameters in the command line that can meet all the calendar requirements you need. Currently, I have not found any calendar that I need to display.

Recommended reading:

History Command records the historical execution time

Linux history commands

Next, I will study these commands with you. These commands are used in Ubuntu Linux:

Question 1: How to display the information of the current month

A: You can directly use the cal command without adding any parameters.

$ 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

Of course, you will also get the same effect when using ncal:

$ ncal    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

You can see the calendar of the current month. The date of the current day is highlighted. You can use the-h parameter to disable the highlighting.

Question 2: How to arrange dates vertically

A: Use the ncal command to add the-J parameter at the same time.

$ 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

Question 3: I want to query the Easter date

A: Use the ncal command to add the-e parameter.

$ ncal -e31 March 2013

4. How to display the Julian Calendar

A: Use the cal command to add the-j parameter.

$ 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

Question 5: how to display the calendar of a specified month

A: Use the cal command to add the-m parameter and month.

$ 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

By default, the-m parameter and month you add are the month of the current year. If you want to see the month of a specified year, you can add the year of the last four digits.

$ 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

6. How to display the calendar of the previous month and the next month at the same time

A: Use the cal command to add the-3 parameter.

$ 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

Similarly, you can view the calendar of any three months:

$ 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

7. How to display information about orthodox Easter

A: Use the ncal command to add the-o parameter.

$ ncal -o 5 May 2013

8. How to display country codes

A: Use the ncal command to add the-p parameter.

$ 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

9. How to display weekly information by calendar month

A: Use the ncal command to add the-w parameter.

$ 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

The bottom line is the information of the next month.

Q 10. How can I view the calendar for the whole year?

A: Use the ncal command to add the-y parameter and the four-digit year.

$ 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

11. How to display the calendar of a month or a few months

A: Use the cal command to add the-m-B-A parameter and the number of months.

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

As you can see, we want to display the calendar of the first two months of January and the last two months of February. To display the calendar of a specified year and the months before and after the year, you must add the-y parameter and the four-digit year:

$ cal -y 2012 -B2 -A2   November 2011         December 2011          January 2012      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  5               1  2  3   1  2  3  4  5  6  7   6  7  8  9 10 11 12   4  5  6  7  8  9 10   8  9 10 11 12 13 14  13 14 15 16 17 18 19  11 12 13 14 15 16 17  15 16 17 18 19 20 21  20 21 22 23 24 25 26  18 19 20 21 22 23 24  22 23 24 25 26 27 28  27 28 29 30           25 26 27 28 29 30 31  29 30 31                 February 2012           March 2012            April 2012       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                       May 2012             June 2012             July 2012        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  5                  1  2   1  2  3  4  5  6  7   6  7  8  9 10 11 12   3  4  5  6  7  8  9   8  9 10 11 12 13 14  13 14 15 16 17 18 19  10 11 12 13 14 15 16  15 16 17 18 19 20 21  20 21 22 23 24 25 26  17 18 19 20 21 22 23  22 23 24 25 26 27 28  27 28 29 30 31        24 25 26 27 28 29 30  29 30 31                  August 2012          September 2012         October 2012      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      1  2  3  4  5  6   5  6  7  8  9 10 11   2  3  4  5  6  7  8   7  8  9 10 11 12 13  12 13 14 15 16 17 18   9 10 11 12 13 14 15  14 15 16 17 18 19 20  19 20 21 22 23 24 25  16 17 18 19 20 21 22  21 22 23 24 25 26 27  26 27 28 29 30 31     23 24 25 26 27 28 29  28 29 30 31                                 30                                             November 2012         December 2012          January 2013      Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa               1  2  3                     1         1  2  3  4  5   4  5  6  7  8  9 10   2  3  4  5  6  7  8   6  7  8  9 10 11 12  11 12 13 14 15 16 17   9 10 11 12 13 14 15  13 14 15 16 17 18 19  18 19 20 21 22 23 24  16 17 18 19 20 21 22  20 21 22 23 24 25 26  25 26 27 28 29 30     23 24 25 26 27 28 29  27 28 29 30 31                              30 31                                          February 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

From the results, we can see the calendar of the last two months of 2012 and the first two months of 2011 in addition to the full year of 2013.

  • 1
  • 2
  • Next Page

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.