Tell me more ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I was wondering if it was possible to add timestamps to terminal prompts, and if so, how could I achieve this?

share|improve this question

3 Answers

up vote 4 down vote accepted

Add this line to the .bashrc file

export PROMPT_COMMAND="echo -n \[\$(date +%H:%M:%S)\]\ "

So the output will be something like:

[07:00:31] user@name:~$

share|improve this answer

Instead of adding the date to the prompt itself, you could add the date just before your prompt by placing the following line at the top of your .bashrc. For it work you will also need to install cowsay. It's a fun way of displaying the date while keeping a short prompt:

cowsay "Welcome $USER! It's now $(date '+%A %B %d %Y %r')"

In its current form it will work on anyone's system without amendment as it reads the $USER and the date variable from the current environment.

enter image description here

share|improve this answer
export PROMPT_COMMAND=date

prints the date before issuing each prompt.

share|improve this answer

Your Answer

 
discard

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.