GNU shell utilities - 9. System context
9. System context
This section describes commands that print or change system-wide information.
9.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.
By default, date pads numeric fields with zeroes.
GNU date recognizes the following numeric modifiers
between the `%' and the directive. These are GNU extensions.
- `-'
- (hyphen) do not pad the field
- `_'
- (underscore) pad the field with spaces
9.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)
- `%S'
- second (00...61)
- `%T'
- time, 24-hour (hh:mm:ss)
- `%X'
- locale's time representation (%H:%M:%S)
- `%Z'
- time zone (e.g., EDT), or nothing if no time zone is determinable
9.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)
- `%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)
- `%x'
- locale's date representation (mm/dd/yy)
- `%y'
- last two digits of year (00...99)
- `%Y'
- year (1970....)
9.1.3 Literal directives
date directives that produce literal strings.
- `%%'
- a literal %
- `%n'
- a newline
- `%t'
- a horizontal tab
9.1.4 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.
9.1.5 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. The source file `getdate.y' implements this parsing for all GNU routines; we need precise documentation!
- `-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
dateexecutable many times can be considerable. - `-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.
9.1.6 Examples of date
Here are a few examples. Also see the documentation for the `-d' option in the previous section.
-
To print the date of the day before yesterday:
date --date='2 days ago'
-
To print the date of the day three months and one day hence:
date --date='3 months 1 day'
-
To print the day of year of Christmas in the current year:
date --date='25 Dec' +%j
-
To print the current full month name and the day of the month:
date '+%B %d'
But this may not be what you want because for the first nine days of the month, the `%d' expands to a zero-padded two-digit field, for example `date -d 1may '+%B %d'' will print `May 01'. -
To print a date without the leading zero for one-digit days
of the month, you can use the (GNU extension)
-modifier to suppress the padding altogether.date -d=1may '+%B %-d'
-
To print the current date and time in the format required by many
non-GNU versions of
datewhen setting the system clock:date +%m%d%H%M%Y.%S
-
To set the system clock forward by two minutes:
date --set='+2 minutes'
9.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:
bash$ 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.
- `-r'
- `--release'
- Print the operating system release.
- `-s'
- `--sysname'
- Print the operating system name.
- `-v'
- Print the operating system version.
9.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.