Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the current date and time in the terminal and set a custom command in the terminal for it? [closed]

I have to check the time in a Linux terminal.

What is the command for getting date and time in a Linux terminal?

Is there a way in which we can set a custom function?

like image 543
harshal Avatar asked Aug 27 '13 06:08

harshal


People also ask

How do I get the current date in Linux terminal?

To use the timedatectl command, type “timedatectl” at the command prompt. This will display the current system time and date settings.

Which command displays current system date and time?

The date command displays the current date and time. It can also be used to display or calculate a date in a format you specify. The super-user (root) can use it to set the system clock.


2 Answers

The command is date

To customise the output there are a myriad of options available, see date --help for a list.

For example, date '+%A %W %Y %X' gives Tuesday 34 2013 08:04:22 which is the name of the day of the week, the week number, the year and the time.

like image 117
Vorsprung Avatar answered Oct 07 '22 08:10

Vorsprung


You can use date to get time and date of a day:

[pengyu@GLaDOS ~]$date
Tue Aug 27 15:01:27 CST 2013

Also hwclock would do:

[pengyu@GLaDOS ~]$hwclock
Tue 27 Aug 2013 03:01:29 PM CST  -0.516080 seconds

For customized output, you can either redirect the output of date to something like awk, or write your own program to do that.

Remember to put your own executable scripts/binary into your PATH (e.g. /usr/bin) to make it invokable anywhere.

like image 95
starrify Avatar answered Oct 07 '22 06:10

starrify