On Unix-like operating systems, the date command is used to print out, or change the value of, the system’s time and date information.

This page covers the GNU/Linux version of date.

Syntax

date [OPTION]… [+FORMAT]

date [-u|–utc|–universal] [MMDDhhmm[[CC]YY][.ss]]

Options

Date format

FORMAT is a sequence of characters which specifies how output appears. It comprises some combination of the following sequences:

  • Syntax
  • Options
  • Date format
  • Examples
  • Related commands
  • Linux commands help

By default, date pads numeric fields with zeroes. The following optional flags may follow ‘%’:

After any flags comes an optional field width, as a decimal number; then an optional modifier, which is either E to use the locale’s alternate representations if available, or O to use the locale’s alternate numeric symbols if available.

Examples

date

Running date with no options outputs the system date and time, as in the following output:

Thu Feb 8 16:47:32 MST 2001

date -s “11/20/2003 12:48:00”

Set the system date and time to November 20, 2003, 12:48 PM.

date “+DATE: %m/%d/%y%nTIME: %H:%M:%S”

Outputs the date and time in the following format:

DATE: 02/08/01TIME: 16:44:55

ls -al > output_$(date +"%m_%d_%Y")

In bash, this command generates a directory listing with ls, and redirect the output to a file which includes the current day, month, and year in the file name. It does this using bash command substitution, running the date command in a subshell and inserting that output into the original command.

time — Report how long it takes for a command to execute.