The date command in Linux: show and configure the date and time

Introduction

The commanddatein Linux is an essential tool to show and configure the date and time of the system. Although it seems simple, its power lies in the multiple format options and its ability to work with time zones and coordinated universal time (UTC). In this article we will explore from the most basic uses to advanced examples that will allow you to manage your machine's time accurately.

Basic date command syntax

The simplest way to usedateis run without arguments, which returns the current date and time according to the time zone set in the system. Its general syntax is:

date [OPTIONS] [+ FORMATE]

WhereOPCIONESchange behavior (such as showing universal time) andFORMATOis a chain that specifies how the output should be presented.

Show current date and time

Run simply:

date

produces an output similar to:

mé sep 25 14: 32: 10 CEST 2025

This default format includes the day of the week, the day of the month, the month, the time, the minutes, the seconds, the time zone and the year.

Custom output format

The true power ofdateis revealed when using the specific+FORMATO. Each pre-finger character by a percentage sign represents a component of the date or time. Some of the most used are:

  • % Y - four-digit year (e.g. 2025)
  • % m - month as decimal number (01-12)
  • % d - day of month (01-31)
  • % H - 24 hour format (00-23)
  • % M - minute (00-59)
  • % S - second (00-59)
  • % a - short name of the day of the week (e.g. vie)
  • % A - full name of the day of the week (e.g. Friday)
  • % b - short name of month (e.g. sep)
  • % B - full name of month (e.g. September)

Examples of common formats

By combining these specifications you can create formats adapted to different needs:

  • For a timestamp ISO-8601:
  • date '+% Y-% m-% dT% H:% M:% S% z'
  • For a legible presentation in Spanish:
  • date '+% A,% d% B of% Y,% H:% M:% S'
  • To include only the date:
  • date '+% F'

Set the date and time of the system

In addition to showing,dateallows the system clock to be adjusted. This operation requires root privileges, so it usually runs withsudo. The syntax to set a new date and time is:

Sudo date MMDDhhmm [[CC] Y] [.ss]

Where:

  • MM - month (01-12)
  • D - day of the month (01-31)
  • hh - time (00-23)
  • mm - minute (00-59)
  • CC - first two digits of the year (optional)
  • YY - last two digits of the year (optional)
  • .ss - seconds (optional)

For example, to set the clock at 25 September 2025 at 14: 30: 00 it would run:

Sudo date 092514302025.00

It is important to synchronize the hardware watch after changing the system date, usinghwclock --systohc.

Use UTC and time zones

The commanddatecan show time in Universal Coordinated Time (UTC) by the option-uor setting the environment variableTZ. For example:

date -u

shows the time UTC, regardless of the local time zone. To work with a specific area without changing the system configuration, you can use:

TZ = 'America / New _ York' date

This is useful in scripts that must operate with dates independent of the server location.

Good practices and security considerations

  • Always check that you have permission to change the system clock; changing the time may affect authentication services, records and programmed tasks.
  • You prefer to use the NTP (Network Time Protocol) protocol to keep the clock automatically synchronized instead of frequent manual settings.
  • When usingdatein scripts, explicitly specify the desired format to avoid surprises due to changes in the regional configuration.
  • Record the time changes in an audit log file.

Conclusion

The commanddateIt is much more than a simple utility to see the time; its capacity to format, adjust and manage time zones makes it an indispensable tool for system managers and developers. Dominating your options will allow you to create consistent records, program tasks accurately and maintain the temporal integrity of your Linux environments. Practice the examples presented and explore the manual page (man date) to discover even more possibilities.

This work is under aCreative Commons License Attribution 4.0 International for Francesc Roig francesc @ vivaldi.net.

EnglishenEnglishEnglish