Linux, date order, format the output, setting time

Help date command

 [root @ localhost source] # date --help
Usage: date [option] ... [+ format]
 or: date [-u | --utc | --universal ] [MMDDhhmm [[CC] YY] [ss. ]]
display the current time, date, or set the system to a given format.

  -d, - date = string display time specified character string as described, instead of the current time
  -f, - file = --date similar file date, the date the file line by line from the read time described
  -r, - -reference = file displays the last modification time of the file specified file
  -R, --rfc-2822 to RFC 2822 format output date and time
                                example: 2006 August 7, -0600 Monday 12:34:56
      --rfc- 3339 = TIMESPEC in RFC 3339 outputs the date and time format.
                                TIMESPEC = `date ',` seconds ', or `ns' 
                                represents a date and time display accuracy.
                                Date and time cells are separated by a single space:
                                2006-08-0712: 34: 56-06: 00
  -s, --set = string is set to separate the time specified string
  -u, --utc, --universal output or set of coordinated Universal Time
      --help display this help and exit
      --version display version information and exit

given the output format fORMAT control explained sequence is as follows:

  % %% a character
  % a week abbreviation of the current locale (e.g.: day, for Sunday)
  % a current locale week full name (e.g.: Sunday)
  % B the current locale month abbreviation (such as: First, on behalf of Jan)
  % B locale's full name of the current month (example: Jan)
  % c locale of the current date and time (eg: March 3, 2005, Thursday 23:05 : 25)
  % C century; such as% Y, is usually the last two digits of the current year are omitted (e.g.: 20 is)
  % D in months date (e.g.: 01)
  % D in months of the date; equals% m / % d /% y
  date% e monthly meter, add a space equal _D%
  % complete date format F., equivalent to Y-% M-% D%
  % G ISO-8601 format the last two years (see% G)
  % G Year of the ISO-8601 format (see% V), generally used in combination, and% V
  % h% b equals
  % H hour (00-23)
  % the I h (00-12)
  % C in terms of by date (001-366)
  when the% k (0-23)
  when L% (1-12)
  % m month (01- 12 is)
  % M points (00-59)
  % n-wrap
  % N nanoseconds (000000000-999999999)
  "am" or "pm" at the locale% p current, the output of the unknown empty
  % P and% p Similarly, the output lowercase
  % r 12 hour clock time (eg: 11: 11:04 pm) currently under the locale
  % when R & lt hours and 24 minutes, equivalent to H%:% M
  % S from UTC time 1970-01-01 the number of seconds elapsed since 00:00:00
  % S seconds (00-60)
  % T output tab the tab
  % of time T, is equal to H%:% M:% S
  % U weeks, 1 for Monday
  % U a the first few weeks of the year, with Sunday as first day (00-53) per week
  the first few weeks of the year at% V ISO-8601 format specification, with Monday as the first day (01-53) per week
  % w the first few days of the week (0-6), 0 represents Monday,
  the first few weeks of the year% W, with Monday as the first day (00-53) per week
  % x current date described in the locale (eg: 12/31/99)
  time% X described in the current locale (eg: 23 is: 13 is: 48)
  % Y year of last two digits (00-99)
  % the Y Year
  % z + hhmm digital time zone (e.g., -0400)
  %: z + HH: mm digital time zone (e.g., 04: 00)
  % :: z + HH: mm: ss digital time zone (e.g., -04: 00: 00)
  % ::: z digital area with the necessary accuracy (e.g., -04, + 05: 30)
  % of the Z ordered alphabetically time zone abbreviation (e.g., the EDT)

in the case, the digital date, in the region filled with zeros by default.
The following selectable markers may follow the "%" after:

  - (hyphen) do not fill the field
  _ (underscore) to fill the space
  0 (number 0) 0 padding
  If possible, use capital letters
  # If possible, use the reverse case

after any optional tag allows a specified field width, it is a decimal number.
As an optional modification of the statement, which may be E, using the associated local environment in case of possible
representation; or is O, using the associated local environment in case of possible numeric symbols.

Time Output

date is the system comes with a Linux system command to display the current system time, but the results in the default display includes a lot of information, especially as the file name when the output is not very convenient
and good command contains date format output options

[python]  view plain  copy
 
  1. [root@root ~]# date "+%Y-%m-%d"  
  2. 2013-02-19  
  3. [root@root ~]# date "+%H:%M:%S"  
  4. 13:13:59  
  5. [root@root ~]# date "+%Y-%m-%d %H:%M:%S"  
  6. 2013-02-19 13:14:19  
  7. [root@root ~]# date "+%Y_%m_%d %H:%M:%S"    
  8. 2013_02_19 13:14:58  
  9. [root@root ~]# date -d today   
  10. Tue Feb 19 13:10:38 CST 2013  
  11. [root@root ~]# date -d now  
  12. Tue Feb 19 13:10:43 CST 2013  
  13. [root@root ~]# date -d tomorrow  
  14. Wed Feb 20 13:11:06 CST 2013  
  15. [root@root ~]# date -d yesterday  
  16. Mon Feb 18 13:11:58 CST 2013  




time setting

We generally use the "date -s" command to change the system time
, such as the system time is set to command July 13, 2011 of: date -s 07/13/2011
the system time is set to 11:12:00 of command: date -s 11:12:00
Note : here that the system time is maintained by the operating system linux.
At system startup, Linux operating system will read the time from the CMOS system time variable, later modified by modifying the system time. In order to maintain the consistency of the system time with the CMOS time, Linux system from time to time will be time to write CMOS. Since the synchronization from time to time (about 11 minutes), and after we implement date -s, if heavy machinery immediately, modification time, there may not have been written to CMOS, this is the cause of the problem.
If you want to make sure that the changes take effect you can execute the following command.
#clock -w
This command forces the system time is written to CMOS.

Guess you like

Origin www.cnblogs.com/runingli/p/10961911.html