How do I show time in Linux?

I need to show time only in Linux. I know date command display both date and time. Is there is any way to get time only in Linux in shell scripts or display it on the screen window?

You can use the date command to show time only.

Display locale’s 12-hour clock time in Linux

date +"%r"

To get 24-hour hour and minute, try:

date +"%R"

Get time in Linux

Open the shell prompt and then type:

date +"%T"

This is same as typing:

date +"%H:%M:%S"
date +"%I:%M:%S"

Where,

  • %H : Hour (00…23)
  • %I : Hour (01…12)
  • %M : Minute (00…59)
  • %S : Second (00…60)

Store time in a shell variable under Linux

#!/bin/bash
NOW_T="$(date +'%T')"
echo "Current time is ${NOW_T}"

How do I get time in Linux command line
See date command man page

man date

Also my tutorial from blog:


Linux sysadmin blog - Linux/Unix Howtos and Tutorials - Linux bash shell scripting wiki