date command in linux will display date and time configured in your linux operating system. We can also set the date and time of the system.
date command syntax -
$ date [OPTION]... [+FORMAT]
To display the current system time and date using the default formatting, invoke the command without any options and arguments -
The output includes the day of the week, month, date of the month, time, time-zone, and year -
Output:Sat Sep 24 13:55:53 EDT 2021
Date String -
- Display FUTURE Dates -
Using -d/- -date Options of date commands
$ date -d/--date="string"
Using -d Option -
Using --date Option -
2. Display PAST Dates -
Date File -
This is used to display the date string present at each line of file in the date and time format.
$ date --file=DATEFILE
Display Last Modified Date -
This is used to display the last modified timestamp of a datefile.
$ date -r DATEFILE
SET Date -
To set the system date and time -s or –set option is used.
$ date --set="Wed Oct 11 15:23:26 PDT 2020"
Date Version Option-
Output version information and exit.
$ date --version
Date HELP Option -
Display the manual of date command.
$ date --help
Date Universal -
Display the Coordinated Universal Time (UTC). Using -u/- -universal Options.
$ date --universal
List of Format specifiers used with date Command:-
%a- Locale’s abbreviated short weekday name (e.g., Mon)
%A- Locale’s abbreviated full weekday name (e.g., Monday)
%b- Locale’s abbreviated short month name (e.g., Jan)
%B- Locale’s abbreviated long month name (e.g., January)
%d- Day of month (e.g., 01)
%H- Hour (00..23)
%I- Hour (01..12)
%j- Day of year (001..366)
%m- Month (01..12)
%M- Minute (00..59)
%S- Second (00..60)
%u- Day of week (1..7)
%Y- Full year (e.g., 2019)
The output of the
date command can be formatted with a sequence of format control characters preceded by a
+ sign. The format controls start with the
% symbol and are substituted by their values.
General Syntax -
Using formatting characters together -
I have made a small efforts to bring some interesting facts, I hope that you have enjoyed the article and learned a new concept today :D.
Thank you for reading my Blog !!.