Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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

Currently my bash prompt looks like this

$ echo $PS1
# \[\e[34m\][\t]\[\e[0m\] \[\e]0;\w\a\]\[\e[34m\]\u@\h: \[\e[34m\]\w\[\e[0m\]\n$

The problem is that \t will only display the time when the prompt was rendered (which would be very close to the time of completion of the last command).

For me, it would be more useful to display the time at which the current command process was started. Is there a way to do this?

share|improve this question
I wonder what difference it will make to your prompt? A few milliseconds cannot cause problems, can they? – phunehehe Oct 24 '10 at 8:20
There are some commands which will take a little bit longer ;-) – echox Oct 24 '10 at 9:45
up vote 6 down vote accepted

If I understand you correctly, you want to change the prompt when you start the current command. I don't think bash has a prompt-changing feature, but you can perhaps redraw over the prompt, if you can locate it (not so easy for multi-line commands).

In zsh, you would use the precmd function. Bash doesn't have a similar feature, but it can be hacked up.

share|improve this answer

No, because there could be any length of time between the prompt and you entering your command, and then pressing the ENTER key.

You could set up an alias for a non command (say doit) that displayed the time and then execute the command it was passed. It would require you remembering to use it every time, and it would only work on systems (and accounts) that you'd configured it on.

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.