coreutils: Padding and other flags
1
1 21.1.4 Padding and other flags
1 ------------------------------
1
1 Unless otherwise specified, ‘date’ normally pads numeric fields with
1 zeros, so that, for example, numeric months are always output as two
1 digits. Seconds since the epoch are not padded, though, since there is
1 no natural width for them.
1
1 As a GNU extension, ‘date’ recognizes any of the following optional
1 flags after the ‘%’:
1
1 ‘-’
1 (hyphen) Do not pad the field; useful if the output is intended for
1 human consumption.
1 ‘_’
1 (underscore) Pad with spaces; useful if you need a fixed number of
1 characters in the output, but zeros are too distracting.
1 ‘0’
1 (zero) Pad with zeros even if the conversion specifier would
1 normally pad with spaces.
1 ‘^’
1 Use upper case characters if possible.
1 ‘#’
1 Use opposite case characters if possible. A field that is normally
1 upper case becomes lower case, and vice versa.
1
1 Here are some examples of padding:
1
1 date +%d/%m -d "Feb 1"
1 ⇒ 01/02
1 date +%-d/%-m -d "Feb 1"
1 ⇒ 1/2
1 date +%_d/%_m -d "Feb 1"
1 ⇒ 1/ 2
1
1 As a GNU extension, you can specify the field width (after any flag,
1 if present) as a decimal number. If the natural size of the output of
1 the field has less than the specified number of characters, the result
1 is written right adjusted and padded to the given size. For example,
1 ‘%9B’ prints the right adjusted month name in a field of width 9.
1
1 An optional modifier can follow the optional flag and width
1 specification. The modifiers are:
1
1 ‘E’
1 Use the locale’s alternate representation for date and time. This
1 modifier applies to the ‘%c’, ‘%C’, ‘%x’, ‘%X’, ‘%y’ and ‘%Y’
1 conversion specifiers. In a Japanese locale, for example, ‘%Ex’
1 might yield a date format based on the Japanese Emperors’ reigns.
1
1 ‘O’
1 Use the locale’s alternate numeric symbols for numbers. This
1 modifier applies only to numeric conversion specifiers.
1
1 If the format supports the modifier but no alternate representation
1 is available, it is ignored.
1