Linux system management and maintenance - date command

  
 

1. The function description shows or modifies the system time and date. Only the superuser can set the time with the date command. Generally, the user can only display the time with the date command. The syntax of the date command is as follows: date [options] Display time format (starting with + followed by time format) The options for the Date command and their descriptions are as follows. — -s --set: Set the system time. — -d --date: Displays the date of the description. The time display format is shown in Table 4.3. Table 4.3 Time Display Format

Format means meaning %H shows hour, indicating range is 00~23 %I Display hour, indicating range is 01~12 %k Display hour, indicating range 0~23 %l Display hour , indicates that the range is 1~12 %M, the display time is 00~59 %S, the display format is 00~59 %p, the display is AM (AM) or PM (PM), %r Display time, the format is hh :mm:ss AM or PM, where hh stands for hour, mm stands for minute, ss stands for second %T display time, format is hh:mm:ss %x displays year and date, format is mm/dd/yyyy, here yyyy Represents the year %X display time format, which is equivalent to %H:%M:%S combination %a shows the day of the week %b or %B shows the month, %b is the abbreviation of the month, and %B is the full name of the month. Month, the format is from 01 to 12% Z. The time zone %d shows the day of the month. %D displays the year and month in the format mm/dd/yy, where yy represents the last two digits of the year, %Y or %. y shows the year, %Y shows the full year, %y shows the last two digits of the year %c shows the date and time format, which is equivalent to “%a The combination of %d %b %Y %r %Z” Example (1) Display the time and date in the specified format. # date '+This date now is:%x, time is now:%X,thanks!'This date now is:07/15/2008, time is now:07:41:35 PM,thanks!(2)Modify system time. [root@mylinux /]# date -s 20080715 Tue Jul 15 00:00:00 CST 2008[root@mylinux /]# date -s 17:25 Tue Jul 15 17:25:00 CST 2008 can also put the above two Merge together. [root@mylinux /]# date -s "20080715 17:25"Tue Jul 15 17:25:00 CST 2008(3) shows the time two days ago. [root@mylinux /]# date '+%Y-%m-%d'2008-07-15[root@server108 /]# date -d "2 days ago" +%Y-%m-%d2008- 07-13

Copyright © Windows knowledge All Rights Reserved