Go to the first, previous, next, last section, table of contents.


10. System context

This section describes commands that print or change system-wide information.

10.1 date: Print or set system date and time

date with no arguments prints the current time and date, in the format of the `%c' directive (described below). Synopses:

date [option]... [+format]
date [-u|--utc|--universal] 
[ MMDDhhmm[[CC]YY][.ss] ]

If given an argument that starts with a `+', date prints the current time and date (or the time and date specified by the --date option, see below) in the format defined by that argument, which is the same as in the strftime function. Except for directives, which start with `%', characters in the format string are printed unchanged. The directives are described below.

10.1.1 Time directives

date directives related to times.

`%H'
hour (00...23)
`%I'
hour (01...12)
`%k'
hour ( 0...23)
`%l'
hour ( 1...12)
`%M'
minute (00...59)
`%p'
locale's AM or PM
`%r'
time, 12-hour (hh:mm:ss [AP]M)
`%s'
seconds since the epoch, i.e., 1 January 1970 00:00:00 UTC (a GNU extension). Note that this value is the number of seconds between the epoch and the current date as defined by the localtime system call. It isn't changed by the `--date' option.
`%S'
second (00...61)
`%T'
time, 24-hour (hh:mm:ss)
`%X'
locale's time representation (%H:%M:%S)
`%z'
RFC-822 style numeric time zone (e.g., -0600 or +0100), or nothing if no time zone is determinable. This value reflects the current time zone. It isn't changed by the `--date' option.
`%Z'
time zone (e.g., EDT), or nothing if no timezone is determinable. Note that this value reflects the current time zone. It isn't changed by the `--date' option.

10.1.2 Date directives

date directives related to dates.

`%a'
locale's abbreviated weekday name (Sun...Sat)
`%A'
locale's full weekday name, variable length (Sunday...Saturday)
`%b'
locale's abbreviated month name (Jan...Dec)
`%B'
locale's full month name, variable length (January...December)
`%c'
locale's date and time (Sat Nov 04 12:02:33 EST 1989)
`%d'
day of month (01...31)
`%D'
date (mm/dd/yy)
`%h'
same as %b
`%j'
day of year (001...366)
`%m'
month (01...12)
`%U'
week number of year with Sunday as first day of week (00...53). Days in a new year preceding the first Sunday are in week zero.
`%V'
week number of year with Monday as first day of the week as a decimal (01...53). If the week containing January 1 has four or more days in the new year, then it is considered week 1; otherwise, it is week 53 of the previous year, and the next week is week 1. (See the ISO 8601: 1988 standard.)
`%w'
day of week (0...6) with 0 corresponding to Sunday
`%W'
week number of year with Monday as first day of week (00...53). Days in a new year preceding the first Monday are in week zero.
`%x'
locale's date representation (mm/dd/yy)
`%y'
last two digits of year (00...99)
`%Y'
year (1970....)

10.1.3 Literal directives

date directives that produce literal strings.

`%%'
a literal %
`%n'
a newline
`%t'
a horizontal tab

10.1.4 Padding

By default, date pads numeric fields with zeroes, so that, for example, numeric months are always output as two digits. GNU date recognizes the following numeric modifiers between the `%' and the directive.

`-'
(hyphen) do not pad the field; useful if the output is intended for human consumption.
`_'
(underscore) pad the field with spaces; useful if you need a fixed number of characters in the output, but zeroes are too distracting.

These are GNU extensions.

Here is an example illustrating the differences:

date +%d/%m -d "Feb 1"
=> 01/02
date +%-d/%-m -d "Feb 1"
=> 1/2
date +%_d/%_m -d "Feb 1"
=>  1/ 2

10.1.5 Setting the time

If given an argument that does not start with `+', date sets the system clock to the time and date specified by that argument (as described below). You must have appropriate privileges to set the system clock. The `--date' and `--set' options may not be used with such an argument. The `--universal' option may be used with such an argument to indicate that the specified time and date are relative to Coordinated Universal Time rather than to the local time zone.

The argument must consist entirely of digits, which have the following meaning:

MM
month
DD
day within month
hh
hour
mm
minute
CC
first two digits of year (optional)
YY
last two digits of year (optional)
ss
second (optional)

The `--set' option also sets the system clock; see the next section.

10.1.6 Options for date

The program accepts the following options. Also see section 2. Common options.

`-d datestr'
`--date=datestr'
Display the time and date specified in datestr instead of the current time and date. datestr can be in almost any common format. It can contain month names, timezones, `am' and `pm', `yesterday', `ago', `next', etc. See section 3. Date input formats.
`-f datefile'
`--file=datefile'
Parse each line in datefile as with `-d' and display the resulting time and date. If datefile is `-', use standard input. This is useful when you have many dates to process, because the system overhead of starting up the date executable many times can be considerable.
`-I[timespec]'
`--iso-8601[=timespec]'
Display the date using the ISO 8601 format, `%Y-%m-%d'. The optional argument timespec specifies the number of additional terms of the time to include. It can be one of the following:
`auto'
The default behavior: print just the date.
`hours'
Append the hour of the day to the date.
`minutes'
Append the hours and minutes.
`seconds'
Append the hours, minutes, and seconds.
If showing any time terms, then include the time zone using the format `%z'. If `--utc' is also specified, use `%Z' in place of `%z'.
`-R'
`--rfc-822'
Display the time and date using the RFC-822-specified format, `%a, %_d %b %Y %H:%M:%S %z'. If `--utc' is also specified, use `GMT' in place of `%z'.
`-r file'
`--reference=file'
Display the time and date reference according to the last modification time of file, instead of the current time and date.
`-s datestr'
`--set=datestr'
Set the time and date to datestr, See `-d' above.
`-u'
`--utc'
`--universal'
Print or set the time and date in Universal Coordinated Time instead of in local (wall clock) time.

10.1.7 Examples of date

Here are a few examples. Also see the documentation for the `-d' option in the previous section.

10.2 uname: Print system information

uname prints information about the machine and operating system it is run on. If no options are given, uname acts as if the -s option were given. Synopsis:

uname [option]...

If multiple options or -a are given, the selected information is printed in this order:

sysname nodename release osversion machine

The osversion, at least, may well be multiple words. For example:

uname -a
=> Linux hayley 1.0.4 #3 Thu May 12 18:06:34 1994 i486

The program accepts the following options. Also see section 2. Common options.

`-a'
`--all'
Print all of the below information.
`-m'
`--machine'
Print the machine (hardware) type.
`-n'
`--nodename'
Print the machine's network node hostname.
`-p'
`--processor'
Print the machine's processor type
`-r'
`--release'
Print the operating system release.
`-s'
`--sysname'
Print the operating system name.
`-v'
Print the operating system version.

10.3 hostname: Print or set system name

With no arguments, hostname prints the name of the current host system. With one argument, it sets the current host name to the specified string. You must have appropriate privileges to set the host name. Synopsis:

hostname [name]

The only options are `--help' and `--version'. See section 2. Common options.


Go to the first, previous, next, last section, table of contents.