Introduction
The Linux command date is a command line utility used to display or set the system date and time. It is one of the most commonly used commands in Linux and is available on all Linux distributions. The date command can be used to display the current date and time, set the system date and time, and convert date and time formats. It can also be used to calculate the difference between two dates and times. This guide will provide an overview of the date command and its various options and arguments.
Examples
The date command in Linux is used to print or set the system date and time.
Syntax:
date [OPTION]… [+FORMAT]
Examples:
1. To print the current date and time:
$ date
2. To print the date in a specific format:
$ date +”%d-%m-%Y”
3. To set the system date and time:
$ date -s “02/14/2020 10:00:00”
The date
command in Linux is used to display the system date and time. It can also be used to set the system date and time. The date command is part of the GNU Core Utilities package, which is installed on all major Linux distributions.
The basic syntax of the date command is:
date [OPTION]... [+FORMAT]
The most commonly used options are:
-d
,--date
– Display or set the system date and time.-s
,--set
– Set the system date and time.-u
,--utc
– Display or set the system date and time in UTC.
The +FORMAT
option allows you to specify the output format of the date command. The most commonly used format specifiers are:
%Y
– Year (4 digits)%m
– Month (2 digits)%d
– Day (2 digits)%H
– Hour (2 digits)%M
– Minute (2 digits)%S
– Second (2 digits)
For example, to display the current date and time in the format YYYY-MM-DD HH:MM:SS
, you can use the following command:
date +"%Y-%m-%d %H:%M:%S"
To set the system date and time to 2020-01-01 12:00:00
, you can use the following command:
date --set="2020-01-01 12:00:00"