Add TimeStamp to command History

Nitiphone

New Member
Joined
May 29, 2019
Messages
6
Reaction score
1
Credits
27
Please kindly help me add date time on history command.

I tried but not work on
1. login root
2. vi /etc/bashrc
#add below command
export HISTTIMEFORMAT='%F %T '

# su - [user]

# echo $HISTTIMEFORMAT

source /etc/bashrc
*****
It can work on time but when I log out and login again. it go back to normal need to run source /etc/bashrc to active the Timestamp again

[root@pcrfocf109 ~]# cat /etc/*release
LSB_VERSION=base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Red Hat Enterprise Linux Server release 6.6 (Santiago)
Red Hat Enterprise Linux Server release 6.6 (Santiago)
[root@pcrfocf109 ~]#
 


Please kindly help me add date time on history command.

1. Add this to your .bash_profile file
Code:
export HISTTIMEFORMAT="%d/%m/%y %T

2. Open a terminal and type
Code:
. .bash_profile
note the dot preceding the .bash_profile line and be sure to use it and hit Enter.

3. Try the history command again and see if it worked.

Hope this helps! :)
 
Please kindly help me add date time on history command.

I tried but not work on
1. login root
2. vi /etc/bashrc
#add below command
export HISTTIMEFORMAT='%F %T '

# su - [user]

# echo $HISTTIMEFORMAT

source /etc/bashrc
*****
It can work on time but when I log out and login again. it go back to normal need to run source /etc/bashrc to active the Timestamp again

[root@pcrfocf109 ~]# cat /etc/*release
LSB_VERSION=base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Red Hat Enterprise Linux Server release 6.6 (Santiago)
Red Hat Enterprise Linux Server release 6.6 (Santiago)
[root@pcrfocf109 ~]#

I use this, both for user ($) and root (#)

Code:
$ / # echo 'export HISTTIMEFORMAT="%F_H-%M-%S "' >> ~/.bashrc
$ / # source ~/.bash_profile

The 2nd command may be replaced by just close and open Terminal again.
 
I tried but some server work but some server not work, Can you guide me a little more?
This Server not work
pcrfocf105$ history | head -1
11 tail -f PCRF5.ES07.GGSN.0_20191004.stat|egrep "DMPRecvMessageCountTPS=|DMPBusyMessageCountTPS="
pcrfocf105$ echo 'export HISTTIMEFORMAT="%F %H:%M:%S "' >> ~/.bashrc
pcrfocf105$ source ~/.bash_profile
pcrfocf105$ history | head -1
14 less PCRF5.ES07.GGSN.0_20191004.stat
pcrfocf105$

This Server Work
[toro@DS4-D20-3 ~]$echo 'export HISTTIMEFORMAT="%F %H:%M:%S "' >> ~/.bashrc
[toro@DS4-D20-3 ~]$source ~/.bash_profile
[toro@DS4-D20-3 ~]$history | head -10
4 2020-08-04 09:44:01 /opt/damocles/sbin/D20CTL db backup -f /opt/damocles/conf/D20_C000_LTC03.yaml
5 2020-08-04 09:44:01 ll
6 2020-08-04 09:44:01 rm -r backup-D20_C000_LTC03-2018-12-11T17\:36\:02+07\:00/
 
Sorry, I can't guide you in server matters, I just remembered the article. :confused:
 


Top