Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I start terminal in Ubuntu, I see:


I need to add a timestamp to this, something like:

2011-10-09T09:32:00 ilya@HOST:~$

How can I configure this?

share|improve this question
up vote 6 down vote accepted

There is a good article about how to change your bash prompt and what all the special symbols (like \h) mean. It also has a link about how to change the colors in you prompt.

As far as applying the changes in your .bashrc, just run source ~/.bashrc

share|improve this answer
Thank you very much for that link! – Ilya Smagin Oct 15 '11 at 11:52

Put this at end of your ~/.bashrc

PS1="\D{%F}T\t $PS1"

Then restart your terminal. For explanations, read manual page of bash, search for ^PROMPTING

(sorry, the first version of this answer reported erroneously single quotes instead of double)

share|improve this answer

To apply the ~/.bashrc change type this inside the running terminal:

exec bash

No need to restart the terminal. This is useful for each change (in the terminal environment)

share|improve this answer

I find that a great setup is to have 3 colourized groups:

  • username & hostname
  • current location
  • current git branch

Plus a newline so you are back to the left side!

enter image description here

You can have all this by having the following in your .bashrc file in your home directory.
Works for Unix and OS X

parse_git_branch () {
  git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[01;33m\]$(parse_git_branch)\[\033[00m\]\n\$ '

If you want this plus your timestamps in four colors you can have:

$ PS1='\033[01;31m\] \D{%F} \t \[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[01;33m\]$(parse_git_branch)\[\033[00m\]\n\$ '

as in:

enter image description here

though personally I think I'll now go with:

parse_git_branch () {
  git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
PS1=$PS1'\[\033[01;34m\]\w\033[00m\]:\033[01;33m\]$(parse_git_branch)\[\033[00m\]\n\$ '


enter image description here

share|improve this answer

To do this temporarily but immediately/on-the-fly, for example so that you can have some privacy while making a screencast, you can do the following

echo PS1='$\ ' > /tmp/ps1 && source /tmp/ps1 && rm /tmp/ps1

The PS1 variable sets the format, source applies that setting by reading from a file.

Now the command line looks like this:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.