Home » Add timestamp to terminal in Linux

Add timestamp to terminal in Linux

by blackMOREOps
1 comment

I came across an issue few weeks back at work when I did some troubleshooting and ran some commands. When I was documenting it, I just couldn’t remember the exact time I started troubleshooting and issued those commands; I mean I even had putty logs saved for 9 hours of troubleshooting data. At that point I really felt the need to add timestamp to terminal so that I would know what I did and when.

vi cheat sheet - logo - blackmore ops

This is our usual Linux terminal or bash shell prompt:

root@kali:~#

Added this line in .bashrc file.

export PROMPT_COMMAND="echo -n \[\$(date +%F-%T)\]\ "

and my Terminal prompt now looks like this:

[2016-10-08-00:47:25] root@kali:~$

So next time, I save the output of my putty or of my terminal session, I would know exactly what I did and when I did.

Pretty neat way and saves a lot of headaches if you ask me. It’s not something new and if you’re like Jeff, then you would know it already… but I am not Jeff and not many people are, so just added this to my list of collection. Enjoy.

You may also like

1 comment

ITPPA October 20, 2016 - 5:45 pm

just for hint, you can include directly in your $PS variable
like this:
export PS1=”[\d \t] ”
[Thu Oct 20 11:33:39]
or this:
export PS1=”[\$(date +%k:%M:%S)] \u@\h\\$ ”
[11:09:56] root@pc$

cheers

Reply

Leave your solution or comment to help others. Comment don't need registration or real email, so feel free.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About Us

blackMORE Ops - touch-icon-72x72

blackMORE Ops” does not promote, encourages and excite hackers, its purpose is to make people aware that what is going around. Know Hacking but No Hacking!

Feature Posts

Newsletter