Linux: Bash Get Time

Linux: Bash Get Time

To get the current time in Bash on a Linux system, you can use the date command.

The date command allows you to display the current date and time in various formats.

Here is an example of how you can use the date command to get the current time:

# Get the current time
time=$(date)

# Print the time
echo "Current time: $time"
Sou‮‬rce:www.lautturi.com

This will output the current time in the format "Fri Dec 10 12:34:56 EST 2021".

You can also use the date command to get the time in a specific format. For example, to get the time in the format "HH:MM:SS", you can use the following command:

# Get the current time in the HH:MM:SS format
time=$(date +%T)

# Print the time
echo "Current time: $time"

This will output the current time in the format "12:34:56".

Overall, the date command is a useful tool for getting the current time in Bash on a Linux system. It allows you to easily display the time in various formats and perform tasks based on the current time.

Created Time:2017-10-30 10:17:43  Author:lautturi