Shell Date Command

Source: Internet
Author: User

Direct run will show time

[Email protected] shell]# Datesat APR 12:56:47 CST 2016

View Calendar

[[email protected] shell]# cal April 2016Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 910 11 12 13 14 15 1617 18 19 20 21 22 2324 25 26 27 28 29 30

View a full year

[[email protected] shell]# cal -y                                 2016       January                February                  marchsu mo tu we th fr  Sa   Su Mo Tu We Th Fr Sa   Su Mo  tu we th fr sa                 1  2       1  2  3   4  5  6          1   2  3  4  5 3  4  5  6  7  8  9     7  8  9 10 11 12 13    6   7  8  9 10 11 1210 11 12 13 14 15 16    14 15 16 17 18 19 20   13 14 15  16 17 18 1917 18 19 20 21 22 23   21 22  23 24 25 26 27   20 21 22 23 24 25 2624  25 26 27 28 29 30   28 29                   27 28 29 30 3131         April                    may                    JuneSu Mo Tu We Th Fr Sa    su mo tu we th fr sa   su mo tu we th  Fr Sa                 1  2    1  2  3  4  5  6   7             1  2   3  4 3  4  5  6  7  8   9    8  9 10 11 12 13 14    5   6  7  8  9 10 1110 11 12 13 14 15  16   15 16 17 18 19 20 21   12 13 14 15 16 17  1817 18 19 20 21 22 23   22 23 24 25 26  27 28   19 20 21 22 23 24 2524 25 26 27  28 29 30   29 30 31                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                 1  2        1  2  3  4  5  6                 1  2  3 3  4   5  6  7  8  9    7  8   9 10 11 12 13    4  5  6  7   8  9 1010 11 12 13 14 15 16   14 15  16 17 18 19 20   11 12 13 14 15 16 1717  18 19 20 21 22 23   21 22 23 24 25 26  27   18 19 20 21 22 23 2424 25 26 27 28  29 30   28 29 30 31             25 26 27 28 29 3031       october                November                decembersu 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                 1  2  3 2  3  4   5  6  7  8    6  7  8  9 10 11 12     4  5  6  7  8  9 10 9  10 11 12 13 14 15   13 14 15 16 17 18  19   11 12 13 14 15 16 1716 17 18 19 20  21 22   20 21 22 23 24 25 26   18  19 20 21 22 23 2423 24 25 26 27 28 29    27 28 29 30            25 26  27 28 29 30 3130 31

Adjust the time (such as adjusted to 2016-4-17 13:02:50)

[Email protected] shell]# date-s "2016-4-17 13:02:50" Sun Apr 13:02:50 CST 2016[[email protected] shell]# Datesun APR 2016 13:03:09 CST

Auto Check time

[[email protected] shell]# yum install-y ntp*[[email protected] shell]# ntpdate time.windows.com with Microsoft Time service 13:06:21 NTPDATE[3580]: The NTP socket is on use, exiting[[email protected] shell]# ntpdate ntp.fudan.edu.cn Time service with Fudan University 13: 07:12 ntpdate[3586]: The NTP socket is on use, exiting


Print the date and time in the specified format with date

F Display Month Day

[Email protected] shell]# date +%f2016-04-16

T Show time

[Email protected] shell]# date +%t13:05:28

Large y shows four-bit years

[Email protected] shell]# date +%y2016

Small y shows a two-bit year

[Email protected] shell]# date +%Y16

M Display Month

[Email protected] shell]# date +%m04

D Show Date

[Email protected] shell]# date +%d16

Show a few points

[Email protected] shell]# date +%h13

Show minutes

[Email protected] shell]# date +%m09

Show seconds

[Email protected] shell]# date +%s52


Show month date including time

[[Email protected] shell]# date + "%y-%m-%d%H: $M:%s" 2016-04-16 13::18


Adjust time (show two days ago)

[Email protected] shell]# date-d "-2 Days" +%f2016-04-14

Adjust time (show two months ago)

[Email protected] shell]# date-d "-2 Month" +%f2016-02-16


Adjust time (show two hours ago)

[Email protected] shell]# date-d "-2 Hour" +%t11:19:04


Adjust time (show two minutes ago)

[[email protected] shell]# date-d "-2 min" +%t13:18:37

Adjust time (show two seconds ago)

[[email protected] shell]# date-d "-2 SEC" +%t13:21:17

Show today is the day of the week

[Email protected] shell]# date +%w6

Show how many weeks until today is the year

[Email protected] shell]# date +%W15

Write a script to generate the log and record the information generated during the script run

[[Email protected] shell]# date +%f2016-04-16[[email protected] shell]# touch 2016-04-16.log[[email protected] shell]# ls 111 123 2016-04-16 2016-04-16.log first.sh

Not to be continued














This article is from "Linux rookie" blog, please be sure to keep this source http://490617581.blog.51cto.com/11186315/1764396

Shell Date Command

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.