[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

21. System context

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

21.1 date: Print or set system date and time  Print or set system date and time.
21.2 uname: Print system information  Print system information.
21.3 hostname: Print or set system name  Print or set system name.
21.4 hostid: Print numeric host identifier.  Print numeric host identifier.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

21.1 date: Print or set system date and time

Synopses:

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

Invoking date with no format argument is equivalent to invoking `date '+%a %b %e %H:%M:%S %Z %Y''.

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.

21.1.1 Time directives  %[HIklMprsSTXzZ]
21.1.2 Date directives  %[aAbBcdDhjmUwWxyY]
21.1.3 Literal directives  %[%nt]
21.1.4 Padding  Pad with zeroes, spaces (%_), or nothing (%-).
21.1.5 Setting the time  Changing the system clock.
21.1.6 Options for date  Instead of the current time.
21.1.7 Examples of date  Examples.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

21.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)
`%N'
nanoseconds (000000000...999999999)
`%p'
locale's upper case `AM' or `PM' (blank in many locales)
`%P'
locale's lower case `am' or `pm' (blank in many locales)
`%r'
time, 12-hour (hh:mm:ss [AP]M)
`%R'
time, 24-hour (hh:mm). Same as %H:%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...60). The range is [00...60], and not [00...59], in order to accommodate the occasional positive leap second.
`%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 time zone is determinable. Note that this value reflects the current time zone. It isn't changed by the `--date' option.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

21.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)
`%C'
century (year divided by 100 and truncated to an integer) (00...99)
`%d'
day of month (01...31)
`%D'
date (mm/dd/yy)
`%e'
blank-padded day of month (1...31)
`%F'
the ISO 8601 standard date format: %Y-%m-%d. This is the preferred form for all uses.
`%g'
The year corresponding to the ISO week number, but without the century (range 00 through 99). This has the same format and value as %y, except that if the ISO week number (see %V) belongs to the previous or next year, that year is used instead.
`%G'
The year corresponding to the ISO week number. This has the same format and value as %Y, except that if the ISO week number (see %V) belongs to the previous or next year, that year is used instead.
`%h'
same as %b
`%j'
day of year (001...366)
`%m'
month (01...12)
`%u'
day of week (1...7) with 1 corresponding to Monday
`%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 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....)


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

21.1.3 Literal directives

date directives that produce literal strings.

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


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

21.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


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

21.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.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

21.1.6 Options for date

The program accepts the following options. Also see 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, time zones, `am' and `pm', `yesterday', `ago', `next', etc. See section 27. 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 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 timespec is omitted with `--iso-8601', the default is `auto'. On older systems, GNU date instead supports an obsolete option `-I[timespec]', where timespec defaults to `auto'. POSIX 1003.1-2001 (see section 2.5 Standards conformance) does not allow `-I' without an argument; use `--iso-8601' instead.

`-R'
`--rfc-822'
Display the time and date using the RFC-822-conforming format, `%a, %_d %b %Y %H:%M:%S %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'
Use Coordinated Universal Time (UTC) by operating as if the TZ environment variable were set to the string `UTC0'. Normally, date operates in the time zone indicated by TZ, or the system default if TZ is not set. Coordinated Universal Time is often called "Greenwich Mean Time" (GMT) for historical reasons.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

21.1.7 Examples of date

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


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

21.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:

 
kernel-name nodename kernel-release kernel-version machine processor hardware-platform operating-system

The information may contain internal spaces, so such output cannot be parsed reliably. In the following example, release is `2.2.18ss.e820-bda652a #4 SMP Tue Jun 5 11:24:08 PDT 2001':

 
uname -a
=> Linux dum 2.2.18ss.e820-bda652a #4 SMP Tue Jun 5 11:24:08 PDT 2001 i686 unknown unknown GNU/Linux

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

`-a'
`--all'
Print all of the below information.

`-i'
`--hardware-platform'
Print the hardware platform name (sometimes called the hardware implementation).

`-m'
`--machine'
Print the machine hardware name (sometimes called the hardware class).

`-n'
`--nodename'
Print the network node hostname.

`-p'
`--processor'
Print the processor type (sometimes called the instruction set architecture or ISA).

`-o'
`--operating-system'
Print the name of the operating system.

`-r'
`--kernel-release'
Print the kernel release.

`-s'
`--kernel-name'
Print the kernel name.

`-v'
`--kernel-version'
Print the kernel version.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

21.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.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

21.4 hostid: Print numeric host identifier.

hostid prints the numeric identifier of the current host in hexadecimal. This command accepts no arguments. The only options are `--help' and `--version'. See section 2. Common options.

For example, here's what it prints on one system I use:

 
$ hostid
1bac013d

On that system, the 32-bit quantity happens to be closely related to the system's Internet address, but that isn't always the case.


[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated by Jeff Bailey on December, 28 2002 using texi2html