Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

A case of using a calendar on the Linux command line

2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail the cases of using calendars on the Linux command line. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

Through the calendar on Linux, you can not only remind you what day it is today. Commands such as date, cal, ncal, and calendar provide a lot of useful information.

The Linux system can help you with your schedule more than just reminding you what day it is today. The calendar shows a lot of options-some may be helpful, some may be an eye-opener.

Date

First of all, you probably know that you can use the date command to display the current date.

$dateMon Mar 26 08:01:41 EDT 2018

Cal and ncal

You can use the cal command to display the entire month. When there are no parameters, cal displays the current month, and by default, highlights the day by reversing the foreground and background colors.

$cal March 2018Su Mo Tu We Th Fr Sa 12 3 4 5 6 7 8 9 1011 12 13 14 15 16 1718 19 20 21 22 23 2425 26 28 29 30 31

If you want to display the current month in horizontal format, you can use the ncal command.

$ncal March 2018Su 4 11 18 25Mo 5 12 19 26Tu 6 13 20 27We 7 14 21 28Th 18 15 22 29Fr 29 16 23 30Sa 3 10 17 24 31

For example, this command may be especially useful if you only want to see the date of a particular week.

$ncal | grep ThTh 1 8 15 22 29

The ncal command can also display a full year in horizontal format, as long as the year is provided after the command.

Ncal 2018 2018 January February March AprilSu 7 14 21 28 4 11 18 25 4 11 18 18 18 15 22 29Mo 18 15 22 5 12 26 5 12 26 29 16 23 30Tu 29 16 23 30 6 13 20 6 13 27 3 17 24We 31 0 17 24 31 7 14 28 21 14 28 4 11 18 25Th 4 11 18 18 18 15 22 18 22 15 29 5 12 19 26Fr 5 12 26 26 16 23 29 16 23 30 6 13 20 27Sa 6 13 20 27 3 10 17 24 3 10 17 24 31 7 14 21 28...

You can also use the cal command to display for a whole year. Remember, you need to enter four digits of the year. If you type cal 18, you will get the calendar year 18 AD instead of 2018.

Cal 2018 2018 January February MarchSu Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa 12 3 4 5 5 6 12 31 23 7 8 9 10 11 12 13 4 5 6 7 8 10 4 5 6 7 9 1014 15 16 17 19 11 12 13 14 14 15 16 17 17 11 12 13 14 14 15 16 17 17 11 12 13 14 15 1721 22 23 26 26 27 18 19 21 21 23 24 18 19 21 21 23 18 19 21 21 23 18 19 21 21 23 19 21 21 23 18 19 21 21 23 18 19 21 21 23 19 21 21 23 19 21 21 23 19 21 21 23 19 21 21 23 19 21 21 23 19 21 21 23 19 21 21 23 19 21 21 23 19 21 21 23 19 21 21 23 19 21 21 23 19 21 21 23 19 21 21 23 19 21 21 23 19 21 21 23 19 21 21 23 19 21 21 23 19 21 21 23 19 21 21 23 19 21 21 23 19 21 21 23 19 21 21 23 19 21 21 23 19 21 21 23 19 21 21 23 Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa 12 3 4 5 6 7 12 3 4 5 12 8 9 10 11 12 13 14 6 7 8 9 10 11 12 3 4 5 6 7 8 915 16 17 18 19 20 21 13 14 15 16 17 18 19 10 11 12 13 14 15 1622 23 24 25 26 27 28 20 21 22 23 24 25 26 17 18 19 20 21 22 2329 30 27 28 29 30 31 24 25 26 27 28 29 30 July August SeptemberSu Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa 12 3 4 5 6 7 12 3 4 18 9 10 11 12 13 14 5 6 7 8 9 10 11 23 4 5 6 7 815 16 17 18 19 20 21 12 13 14 15 16 17 18 9 10 11 12 13 14 1522 23 24 25 26 27 28 19 20 21 22 23 24 25 16 17 18 19 20 21 2229 30 31 26 27 28 29 30 31 23 24 25 26 27 28 29 30 October November DecemberSu Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa 12 3 4 5 6 12 31 7 8 9 10 11 12 13 4 5 6 7 8 9 10 23 4 5 6 7 814 15 16 17 18 19 20 11 12 13 14 15 16 17 9 10 11 12 13 14 1521 22 23 24 25 26 27 18 19 20 21 22 23 24 16 17 18 19 20 21 2228 29 30 31 25 26 27 28 29 30 23 24 25 26 27 28 29 30 31

To specify the year and month, use the-d option, as follows:

Cal-d 1949-03 March 1949Su Mo Tu We Th Fr Sa 12 3 4 5 6 7 8 9 10 11 1213 14 15 16 17 18 1920 21 22 23 24 2627 28 29 30 31

Another potentially useful calendar option is the-j option of the cal command. Let's see what it shows.

Cal-j March 2018 Su Mo Tu We Th Fr Sa 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 76 77 78 79 80 81 82 84 85 86 87 88 89 90

You might ask, "what the heck?" The OK,-j option displays the Julian date-a numeric date from 1 to 365 years of the year. So, 1 is January 1, and 32 is February 1. The command cal-j 2018 will display numbers for the whole year, like this:

$cal-j 2018 | tail-9 November December Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa 305 306 307 335308 309 310 311 313 314 336 337 338 339 340 342315 316 317 319 319 321 343 344 345 346 347 349322 323 326 327 328 326 352 352 354 355 356329 331 332 333 357 357 358 361 362 363 36365 365

This display may help remind you how many days you haven't taken action since you made your New year's resolution.

Run a similar command, and for 2020, you'll notice that this is a leap year:

$cal-j 2020 | tail-9 November December Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa306 307 308 309 310 311 312 336 337 338 339 340313 314 315 317 318 341 343 344 346 347320 321 322 323 325 326 348349 351 352 354327 328 329 331 332 355 356 358 359 361334 335 362 364 365 366

Calendar

Another interesting but potentially frustrating command can tell you about holidays, which has a lot of options, but here's a list of upcoming holidays and calendars that you want to see. The-l option of the calendar allows you to select the number of days you want to view today, so 0 means "today only".

$calendar-l 0Mar 26 Benjamin Thompson born, 1753, Count Rumford; physicistMar 26 David Packard died, 1996 Age of 83Mar 26 Popeye statue unveiled, Crystal City TX Spinach Festival, 1937Mar 26 Independence Day in BangladeshMar 26 Prince Jonah Kuhio Kalanianaole Day in HawaiiMar 26 * Seward's Day in Alaska (last Monday) Mar 26 Emerson, Lake, and Palmer record "Pictures at an Exhibition" live, 1971Mar 26 Ludwig van Beethoven dies in Vienna, Austria, 1827Mar 26 Bonne f ê te aux Lara! Mar 26 Aujourd'hui, c'est la St (e) Ludger.Mar 26 N'oubliez pas les Larissa! Mar 26 Ludwig van Beethoven in Wien gestorben, 1827Mar 26 Emá nuel

For most of us, it's a bit of a celebration. If you see something like this, you can blame it on your calendar.all file, which tells the system which international calendars you want to include. Of course, you can reduce this problem by deleting some lines in this file that contain other files. The file looks like this:

# include # include

Suppose we switch our display to the World Calendar only by removing all lines except the first # include line shown above. We'll see this:

$calendar-l 0Mar 26 Benjamin Thompson born, 1753, Count Rumford; physicistMar 26 David Packard died, 1996; age of 83Mar 26 Popeye statue unveiled, Crystal City TX Spinach Festival, 1937Mar 26 Independence Day in BangladeshMar 26 Prince Jonah Kuhio Kalanianaole Day in HawaiiMar 26 * Seward's Day in Alaska (last Monday) Mar 26 Emerson, Lake, and Palmer record "Pictures at an Exhibition" live, 1971Mar 26 Ludwig van Beethoven dies in Vienna, Austria, 1827

Obviously, there are many special days in the world calendar. But a display like this allows you not to forget all the important unveiling days of Popeye and its role in celebrating the spinach capital of the world.

A more useful calendar choice might be to put a work-related calendar in a special file and use it in the calendar.all file to determine which events you will see when you run the command.

$cat / usr/share/calendar/calendar.all/* * International and national calendar files * * This is the calendar master file. In the standard setup, it is * included by / etc/calendar/default, so you can make any system-wide * changes there and they will be kept when you upgrade. If you want * to edit this file, copy it into / etc/calendar/calendar.all and * edit it there. * * / # ifndef _ calendar_all_#define _ calendar_all_#include # include

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report