Bash Show time in terminal prompt


Example

timeNow(){
    echo "$(date +%r)"
}
PS1='[$(timeNow)] \u@\h:\w$ '

It will give you a prompt like this:

[05:34:37 PM] user@Host:/path$ 

Notes:

  • Make the changes in ~/.bashrc or /etc/bashrc or ~/.bash_profile or ~./profile file (depending on the OS) and save it.
  • Run source ~/.bashrc (distro specific) after saving the file.