How to print the current date and time in BASH shell scripts

Sometimes it’s useful to print the current time and date in a BASH script. We can make use of the date command for that. By default, and if called without any parameters, it’ll print something like this:

We can shorten this to just the date by using a formatting shortcut like this:

or just the time using this format:

Formatting shortcuts can also be used together, like so:

For a complete list of shortcuts, try “man date” from the command line.

About Jay Versluis

Jay is a medical miracle known as a Super Survivor. He runs two YouTube channels, five websites and several podcast feeds. To see what else he's up to, and to support him on his mission to make the world a better place, check out his Patreon Campaign.

Add your voice!