Wondering how to find Date And Time In Linux Terminal Using Date Command? Looking for a date and time Linux terminal command?
Linux is an open-source and community-developed operating system. It can be used for various computers, servers, mainframes, mobile devices, and embedded devices. It supports various computer platforms making it one of the widely supported operating systems.
The Linux Terminal commands is a utility of the Linux operating system. All tasks can be done by executing the Linux terminal commands. Linux commands are case-sensitive.
The date command in Linux is used to display the system date and time. This command can be even used to set the date and time of the system. By default, to Date And Time In Linux Terminal Using Date Command in the time zone on which Unix/Linux OS is configured.
date [OPTION]… [+FORMAT]
date [-u|–utc|–universe] [MMDDhhmm[[CC]YY][.ss]]
This article will guide you on how to display the date and time in Linux Terminal using the date command.
To run the default date Linux terminal command and to print the current date and time of your timezone. Use the “date” command. The default formatting might look a bit messy and look like it it’s a serious rearrange as the year is behind the timezone. But, if you wish to rearrange the format and want output in a few specific arrangements themselves, then don’t worry.
Linux Terminal has more than 40 options to print output however you want.
Input: ~$ date
Output: Sun Jul 12 16:08:45 EDT 2021
To sort files concerning the last modified date and time. The ls displaying date and time Linux terminal will list all the files in a directory. To do this making use of the “-t” like shown below:
Input: ~$ ls -lt
Output: all the files in a dictionary will be listed
And if you wish to reverse the sorting files, then use the “-r” command like:
Input: ~$ls -ltr
Output: files will be listed in reverse order.
To display date and time in Linux Terminal using the date command in the local format you will have to add “%c” after the date and the “%c” command must be followed by a “+” sign. The output will be printed in the normalized format with respect to your locale. Your locale will be set when you installed the Linux operating system. The locale covers things like currency symbols, paper sizes, timezone, etc.
Input: ~$ date +%c
Output: Sun 13 Jul 2021 04:09:03 PM EDT
The date command allows passing several options to the “date” command, a sequence of options is called a format string. To display the name of the day, the day of the month, and the month name, use:
Input: ~$ date +%A%d%B or ~$ date +”%A %d %B” or ~$ date +”Today is: %A %d %B”
Output: Sunday13July or Sunday 13 July or Today is: Sunday 13 July
You can format the output “date” in three ways:
Input: ~$ date +%D ~$ date +%F ~$ date +%x
Output: 04/07/21 2021-04-07 04/07/2021
Input: ~$ date +%U ~$ date +%V ~$ date +%W
Output: 14 14 13
Input: ~$ date +%b ~$ date +%h ~$ date +%B ~$ date +%m
Output: Apr Apr April 04
Input: ~$ date +%T ~$ date +%R ~$ date +%r ~$ date +%X
Output: 16:15:55 16:16 04:16:06 PM 04:16:06 PM
To Display the Hour in Linux Terminal
Input: ~$ date +%H ~$ date +%I
Output: 16 04
To display the minute on the Linux terminal screen give the “%M” command. It will display the outputs with a leading zero if required like 01, 02, 03, …. 59.
Input: ~$ date +%M
Input: ~$ date +%s ~$ date +%S ~$ date +%N
Output: 1554668298 21 500161856
That said, hope this article helped you with your code. There are more formats to display Date And Time In Linux Terminal Using Date Command.
Subscribe to our Newsletter