Mon 27 Nov 2006
Set time for history command in linux.
Posted by Dave under Dedicated Server Hosting , Linux Web Hosting , Server SecurityIf you are using a bash shell then using following command you can set the time in history so that you will get a better idea at what time the command was fired.
HISTTIMEFORMAT=â€%D %T â€
If you have ksh doesn’t have any feature intended to put timestamps in history. You can get a similar effect by combining the evaluation of the PS1 prompt and the “read -s†feature that reads into history.
PS1=’$(printf “%(# %D %T )T†| read -s)$ ‘
This prompt setting will put the current date and time into the history each time ksh comes back to printing a prompt. The timestamp will appear as a separate line. It will show the time that the preceeding command completed. You won’t be able to know exactly when a long-running command was started. (The bash timestamp feature shows the start times of entered commands and doesn’t show when they finish.)
You can also try following step.
HST=`hostname`
USR=`who -um | awk ‘{print $1}’`
NAME=`whoami`# Set History File
HISTFILE=/home/root/.sh_history_â€${HST}â€_â€${USR}â€-as-â€${NAME}â€_`date +%y%m%d.%
H%M%S_$$`
export HISTFILE
Thats it.
One Response to “Set time for history command in linux.”
Leave a Reply
You must be logged in to post a comment.



















August 12th, 2007 at 12:49 pm
Thank you for the tip. You saved me a lot of wading through man pages. I just typed ‘bash “time in history”‘ to google and your page was fourth from the top. And the command works great. Thanks for sharing! –Kevin