Showing Current Time in Bash Prompt

Sometimes, you wish you had started a long running command with the time command. Either you have to abort and rerun the command, or you can use the following simple trick:

First, open ~/.bash_aliases in your favorite editor (nano comes to mind). Then add the line shown below so that you insert \t (the current time including seconds in 24-hour format) where you want it. I inserted it right at the start, followed by a single space.

PS1='\t ${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\> '

If you want to check out the possible escaped characters that Bash understands, type man bash and then search for the section PROMPTING. There you'll find a complete list of prompt variables to use, including 12-hour clock formats and more.