Linux date command: how to set, change, format and display date

Linux date command: how to set, change, format and display date

Hello colleagues.

In today's article, we're going to talk about the  command in Linux, date. With this command, you can display and set the system date and time. The date command also allows you to display the time in various formats.

 

Article content:

  1. Command syntax.
  2. Formatting characters.
  3. Examples.

 

1. Command syntax.

date [option] .... [format]

The [option] and [format] parameters are optional and can therefore be omitted.


 

 

2. Formatting characters.

Most used formatting characters:

  • +%D - Displays date in mm/dd/yy format
  • +%Y - Year (For example 2022)< /span>
  • +%m - Month (01-12)< /span>
  • +%B - Full name of the month (e.g. May)
  • +%b - Short month name (e.g. May)
  • +%d - Day of the month (e.g. 01)
  • +%j - Day of the year (001-365)
  • +%u - Day of the week (1-7)
  • +%A - Full name of the day of the week (e.g. Monday)
  • +%a - Short name of the day of the week (e.g. Mon)
  • +%H - Hour (00-23)< /span>
  • +%I - Hour (01-12)< /span>
  • +%M - Minute (00-59)< /span>
  • +%S - second (00-60)< /span>

Example: date "+%D" - The result will be: 05/ 30/22


 

3. Examples.

3.1. Easy to use date without parameters.

$. date

linux_command_date

 

3.2. Show the time the file was last modified.

$. date -r /mariadb/config/config-file.cnf

linux_command_date

 

3.3. Show what year, month and day it is.

$. date +"Year: %Y, Month: %m, Day: % d"

linux_command_date


 

Thank you all, I hope my article was of some help to you.

SIMILAR ARTICLES

mv command in linux. Moving/Renaming files.
mv command in linux. Moving/Renaming files.
TERMINAL
Read more
tail command in linux. View the last lines of a file.
tail command in linux. View the last lines of a file.
TERMINAL
Read more
Linux command cal, calendar
Linux command cal, calendar
TERMINAL
Read more