Linux: Bash Get Time

In Linux, you can use the date command in the bash shell to get the current time. The default format of the date command is the system’s local time, which is usually set by the administrator during the installation of the operating system.

Here’s an example of using the date command to get the current time in the default format:

$ date
Mon Feb 14 15:42:56 EST 2022

You can use the + option and format codes to customize the output format of the date command. For example, to get the current time in the format “HH:MM:SS”, you can use the following command:

$ date +%T
15:42:56

Here, the %T format code specifies that the output should be in the format “HH:MM:SS”. There are many other format codes available, which you can use to display the date, time, and various other information in a variety of formats.

You can also use the date command in scripts and programs to automate tasks that require the current time. For example, you might use the date command to log the time that a certain task was performed, or to schedule tasks to run at specific times.

Leave a Comment