Click on any of the 687 commands below to get a description and list of available options. All links in the command summaries point to the online version of the book on Safari Bookshelf.
Print the current date and time. You may specify a display format. format can consist of literal text strings (blanks must be quoted) as well as field descriptors, whose values will appear as described in the following entries (the listing shows some logical groupings). A privileged user can change the system's date and time.
Options
+format
Display current date in a nonstandard format. For example:
$date +"%A %j %n%k %p"
Tuesday 248
15 PM
The default is %a %b %e %T %Z %Y (e.g., Tue Sep 5 14:59:37 EDT 2005).
-ddate, --datedate
Display date, which should be in quotes and may be in the format ddays or mmonthsddays, to print a date in the future. Specify ago to print a date in the past. You may include formatting (see the following section).
-fdatefile, --file=datefile
Like -d, but printed once for each line of datefile.
-I [timespec] , --iso-8601[=timespec]
Display in ISO-8601 format. If specified, timespec can have one of the following values: date (for date only), hours, minutes, or seconds to get the indicated precision.
-rfile, --reference=file
Display the time file was last modified.
-R, --rfc-822
Display the date in RFC 822 format.
--help
Print help message and exit.
--version
Print version information and exit.
-sdate, --setdate
Set the date.
-u, --universal
Set the date to Greenwich Mean Time, not local time.
Format
The exact result of many of these codes is locale-specific and depends upon your language setting, particularly the LANG environment variable. See locale.
%
Literal %.
- (hyphen)
Do not pad fields (default: pad fields with zeros).
_ (underscore)
Pad fields with space (default: zeros).
%a
Abbreviated weekday.
%b
Abbreviated month name.
%c
Country-specific date and time format.
%d
Day of month (01-31).
%h
Same as %b.
%j
Julian day of year (001-366).
%k
Hour in 24-hour format, without leading zeros (0-23).
%l
Hour in 12-hour format, without leading zeros (1-12).
%m
Month of year (01-12).
%n
Insert a new line.
%p
String to indicate a.m. or p.m.
%r
Time in %I:%M:%S %p (12-hour) format.
%s
Seconds since "the Epoch," which is 1970-01-01 00:00:00 UTC (a nonstandard extension).
%t
Insert a tab.
%w
Day of week (Sunday = 0).
%x
Country-specific date format based on locale.
%y
Last two digits of year (00-99).
%z
RFC 822-style numeric time zone.
%A
Full weekday.
%B
Full month name.
%D
Date in %m/%d/%y format.
%H
Hour in 24-hour format (00-23).
%I
Hour in 12-hour format (01-12).
%M
Minutes (00-59).
%S
Seconds (00-59).
%T
Time in %H:%M:%S format.
%U
Week number in year (00-53); start week on Sunday.
%V
Week number in year (01-52); start week on Monday.
%W
Week number in year (00-53); start week on Monday.
%X
Country-specific time format based on locale.
%Y
Four-digit year (e.g., 2006).
%Z
Time-zone name.
Strings for setting date
Strings for setting the date may be numeric or nonnumeric. Numeric strings consist of time, day, and year in the format MMDDhhmm[[CC] YY] [.ss] . Nonnumeric strings may include month strings, time zones, a.m., and p.m.
time
A two-digit hour and two-digit minute (hhmm); hh uses 24-hour format.
day
A two-digit month and two-digit day of month (MMDD); default is current day and month.
year
The year specified as either the full four-digit century and year or just the two-digit year; the default is the current year.
Examples
Set the date to July 1 (0701), 4 a.m. (0400), 2005 (05):