date [option]... [ +format] - display or set date and time
date [-nu] [-r seconds] [+format]
date [[[[[cc]yy]mm]dd]hh]mm[.ss]
+ prefixes format codes or arbitrary text (ex :, / ).
A <newline> is appended to the string.
N.B. If used in crontab command fiels, % must be escaped.
| The default format is: | "%a %b %e %H:%M:%S %Z %Y" |
| sample output: | Sat Feb 5 18:09:28 EST 2005 |
Useful forms:
export TODAY=`date +%y%m%d`
date +"%m/%d %H:%M" 07/20 18:56
export LOGYYMMDDHHMM=`date +%y%m%d%H%M` 0807201859
touch `date +%y-%m-%d_%H:%M` 10-12-31_23:59
Without the + , date uses the argument for setting the system's date if user has sufficient authorization.
-r, --reference=file output the modification time of file
format codes:
(arranged by function, not alphabetically)
%m mm month (01..12) (how to blank padded?? ie ' 1, 2, 3' vs '01,02,03' ?? )
%h Mon %b locale's abbreviated month (Jan..Dec)
%B locale's full month, variable length ex:(January..December)
%d dd (01..31) %e ( 1..31)
%y yy two digit year (00..99)
%Y ccyy year (1970...) %C cc century [00-99]
%g 2-digit year corresponding to the %V week number %G 4-digit
%F %Y-%m-%d
| for this locale | |
%D mm/dd/yy | %x mm/dd/yy
|
%T hh:mm:ss 24-hour | %X %H:%M:%S
|
%R 24-hour (hh:mm)
%r time, 12-hour (hh:mm:ss x.M)
%I HH hours (01..12) %l† 1..12 %H 00..23 %k 0..23 %p upper case AM or PM (blank in many locales) %P lower case am or pm %M MM minutes (00..59) %S SS second (00..60)) The 60 is necessary to accommodate a leap second %N nanoseconds (000000000..999999999) %c locale's date and time ex: Sat Nov 04 12:02:33 EST 1989 %j day of year (001..366) %u day of week (1..7); 7 represents Sunday mtwtfss %w (0..6); 0 represents Sunday smtwtfs %a locale's abbreviated weekday (Sun..Sat) %A locale's full weekday, variable length (Sunday..Saturday) %U week number Sunday as first day of week (00..53) %W week number Monday as first day of week (00..53) %V (01..53) %z -zzzz RFC-822 style numeric timezone (-0500) %:z +hh:mm numeric timezone (e.g., -04:00) %::z +hh:mm:ss numeric time zone (e.g., -04:00:00) %:::z numeric time zone with : to necessary precision (e.g., -04, +05:30)%Z time zone (e.g., EDT) nothing if no time zone is determinable %s seconds since 00:00:00 1970-01-01 UTC
literals: %n newline ; %% percent; %t horizontal tab
By default, date pads numeric fields with zeroes.
GNU (not BSD) date recognizes the following modifiers between `%' and a numeric directive.
- (hyphen) do not pad the field _ (underscore) pad the field with spaces
example: %_H == %k
%-m/%-d/%y 1/2/50
TZ Specifies the timezone, unless overridden by command line parameters.
If neither is specified, the setting from /etc/localtime is used.
-d, -de=STRING display time described by STRING, not now.
-e=datefile like de once for each line of datefile
-s, --set=string set time described by string
date -s "2010-12-31 23:59:00"
-n don't synchronize the clocks on groups
of machines using the utility timed(8). By default, if timed is running, date will set the time on all of the machines in the local group. -n inhibites that.
date and time seconds from the Epoch. ( i.e. Dec 31 19:00:00 EST 1969 )
-u Display or set the date in UTC (universal) time.
date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]
The only valid option for the this form specifies Coordinated Universal Time.
-u GMT ex: Sat Feb 5 14:49:42 GMT 2005
--utc, --universal Coordinated Universal Time local TZ Sat Feb 5 09:49:59 EST 2005
-ITIMESPEC, --iso-8601[=TIMESPEC] output date/time in ISO 8601 format.
TIMESPEC=date for date only, `hours', `minutes', or `seconds' for date and time to the indicated precision.
--iso-8601 without TIMESPEC defaults to `date'.
-R, --rfc-822 output RFC-822 compliant date string ex: Sat Feb 5 09:50:23 EST 2005
--help display this help and exit
--version output version information and exit
from BSD documentation of date and strtime on apple OS X
date (coreutils) 4.5.3
Linux: date (GNU coreutils) 5.97 Copyright (C) 2006