Linux, -date display or set the time

Options
-d output time the specified string, such as -d DATE "1990/09/18"
-f progressive output time the specified file
-I [TIMESPEC] date / time in ISO 8601 format. TIMESPEC as "date" (only the date), "hours", "minutes ", "senconds" ( display time accuracy) one, the default is "date".
-r displays the specified file was last modified
-R accordance with RFC-2822日期格式显示时间
-s time set in accordance with the specified string
-u according to Coordinated Universal Time (UTC) format or to output time

The format parameter format
%% a literal%
Note: The output is a% symbol
% a locale's abbreviated weekday name ( eg, Sun)
Note: The days of the week, such as Saturday, Sat, Sun the Sun
% A locale's full weekday name ( eg, Sunday )
Note: the full name of the day of the week, such as Sunday Sunday
% b locale's abbreviated month name ( eg, Jan)
Note: the abbreviation for the month, as Aug Aug
% B locale's full month name ( eg, January)
Note: the full name of the month, The September September
% c locale's date and time ( eg, Thu Mar 3 23:05:25 2005)
Note: the date and time output
% C century; like% Y, except omit last two digits (eg, 20)
Note: output rounded the century, divided by one hundred years, as 2016 is the 20th century after the conversion. . .
% d day of month (eg, 01)
Note: The first day of the month, two digits represented. The No. 1, it displays 01
% D DATE; Same AS% m /% d /% y
Note: According% m /% d /% y format output date, such date "+% D" output is a 09/08 / 16
% e day of month, space padded ; same as% _d
NOTE: The first day of the month, the digital representation. The No. 1, then the display 1
% F. Full DATE; Same AS% Y-% m-% d
Note: According% Y-% m-% d complete date output format, such as the date "+% F", 2016-09- 08
% G tWO Last year of digits of the ISO Week number (See G%)
Note: the year (yy), the output of the last two digits of the year
% G year of ISO week number ( see% V); normally useful only with% V
Note: Year (YYYY)
% H% B same AS
NOTE: Abbreviation input month, with B%
% H hour (00..23)
Note: the 24-hour, 23 is ~ 00
% the I hour (01..12)
Note : 12-hour, 01 to 12, such as date -d '00: 00: 11 ' "+% I", displayed 12
% of Day J year (001..366)
Note: the first day of the year, The three figures
% k hour, space padded (0..23 ); same as% _H
Note: The 24-hour, expressed numerically, ~ 23 is 0
% L hour, Space padded (1..12); Same AS% _I
Note: The 12-hour, expressed numerically, such as the date -d '01: 01: 11 ' "+% I", the output of 01
% m month The (01..12)
Note: the month, two digits represented, such as a month 01 represents a
% M minute (00..59)
Note: minutes, two digits
% na newline
Note: wrap
% N nanoseconds (000000000..999999999)
Note: ns output
% p locale's equivalent of either AM or PM ; blank if not known
NOTE: morning or afternoon output uppercase current time, such as AM, the PM
% P like% P, But Lower Case
Note: AM output lowercase current time or afternoon, such as AM, PM
% R & lt the locale apos 12 is -hour clock time (eg, 11:11:04 PM )
Note: according to the output of the 12-hour period, such as date "+% r", the output of AM 11:44:57
% R & lt hour and 24-hour minute; Same aS% H:% M
Note: Following the 24-hour output of the hour and minute, and% H:% M isotype effect of
% s seconds since 1970-01-01 00:00:00 UTC
NOTE: since 1970-01-01 00:00 : 00 seconds to the current UTC began
% S second (00..60)
Note: sec, 00 ~ 60
% ta tab
Note: a Tab, space corresponds to the output 8
% T time; same as% H :% M:% S
NOTE: output time, and% H:% M:% S with the results, date "+% F % T ", the output of 11:48:27 2016-09-08
% U Day of week (1..7); 1 iS catalog on Monday
Note: The digital output of the week, Monday 1 to 7,1
% U week number of year, with Sunday as first day of week (00..53)
Note: the first few weeks of the year, Sunday is the first day of the week, 00 ~ 53
% V week Number the ISO, AS catalog on Monday with first day of week (01..53)
Note: Week ISO format, the first few weeks of the year, first day of the week is Monday, 53 is ~ 00
% W day of Week (0..6); iS the Sunday 0
Note: the digital output of the week, Sunday is 0 to 6,0
% W week number of year, with Monday as first day of week (00..53)
Note: the first few weeks of the year, the first Monday of the week day, 53 is ~ 00
% the locale apos dATE representation X (eG, 12/31/99)
Note: The output date, e.g. 12/31/99,
% X-Time representation apos the locale (eG, 23:13:48)
NOTE: output time, such as 23:13:48
% Last TWO digits of year Y (00..99)
Note: two years after output
% Y year
Note: Output Year

Examples

Output time according to the specified format
* date "+%Y-%m-%d %H:%M:%S"
2016-09-08 13:48:24

##### 输出指定的字符串
* date -d "2016-09-08 13:48:24" "+%F %T"
2016-09-08 13:48:24

* date -d "2016-09-08 13:48:24" "+%x"
09/08/2016

##### 后一天的时间
* date -d next-day "+%F %T"
2016-09-09 13:59:38

* date -d tomorrow "+%F %T"
2016-09-09 14:05:15

##### 前一天的时间
* date -d last-day "+%F %T"
2016-09-07 14:03:56

* date -d yesterday "+%F %T"
2016-09-07 14:03:56

##### 更多
* date -d next-month "+%F %T"
2016-10-08 14:06:42

* date -d next-year "+%F %T"
2017-09-08 14:07:26

* date -d "5 days ago" "+%F %T"
2016-09-03 14:08:31

* date -d week "+%F %T"
2016-09-15 14:17:37

* date -d "Nov 12 - 2 days" "+%F %T"
2016-11-10 00:00:00

* date -d "12/12 - 2 days" "+%F %T"
2016-12-10 00:00:00

* date -d "2 days" "+%F %T"
2016-09-10 14:24:34

##### 设置时间
* 设置完整的时间
* date -s "2016-09-10 14:24:34"

* 设置日期
* date -s "2016-09-10"
* date -s "2016/09/10"
* date -s "09/10/2016"
这样设置的话,由于没有设置时间,所以时间都是00:00:00

##### 显示文件最后修改时间
* date -r /bin
Wed Aug 31 15:58:16 HKT 2016

##### 显示文件的时间
* more date.txt 
2016-02-10 19:11:11
2016-10-11 17:22:33
2014/12/11 13:11:11

* date -f date.txt
Wed Feb 10 19:11:11 HKT 2016
Tue Oct 11 17:22:33 HKT 2016
Thu Dec 11 13:11:11 HKT 2014

* date -f date.txt "+%F %T"
2016-02-10 19:11:11
2016-10-11 17:22:33
2014-12-11 13:11:11

Guess you like

Origin www.cnblogs.com/Anesthesia-is/p/12585772.html