Bash - How to get date time

By xngo on June 17, 2019

In Bash, you can get the date and time using the command date. You can use it to form a more or less unique filename. Here is the code.

date_string=$(date +"%Y-%m-%d.%0k.%M.%S")
echo ${date_time}

Output

2019-06-17.14.16.54

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.