Scenario: How to display date and time in bash history command on CentOS/RHEL.
By default default history command output didn’t show date and time.
[bachem@centos7ht ~]$ history 1 sudo su 2 su - 3 sudo su 4 su - 5 ulimit -a
Below how to setup display date and time in history bash command.
– Steps to setup on a single user,example on bachem user
$ echo 'HISTTIMEFORMAT="%F %T "' >> /home/bachem/.bash_profile
it will add HISTTIMEFORMAT="%F %T "
in the bottom file /home/bachem/.bash_profile.
then run below command to apply
$ source /home/bachem/.bash_profile
Now when run history will show date and time on each bash command.
[bachem@centos7ht ~]$ echo 'HISTTIMEFORMAT="%F %T "' >> /home/bachem/.bash_profile [bachem@centos7ht ~]$ source /home/bachem/.bash_profile [bachem@centos7ht ~]$ history 1 2017-10-09 15:45:38 sudo su 2 2017-10-09 15:45:38 su - 3 2017-10-09 15:45:38 sudo su 4 2017-10-09 15:45:38 su - 5 2017-10-09 15:45:38 ulimit -a
– Steps to setup for system wide all users.
1) Login as root
2) Run below command
# echo 'HISTTIMEFORMAT="%F %T "' >> /etc/profile
it will add HISTTIMEFORMAT="%F %T "
in the bottom file /etc/profile.
then run below command to apply
# source /etc/profile
Now when run history will show date and time on each bash command.
[root@centos7ht ~]# echo 'HISTTIMEFORMAT="%F %T "' >> /etc/profile [root@centos7ht ~]# source /etc/profile [root@centos7ht ~]# history 1 2017-10-09 16:53:33 yum install bind-utils 2 2017-10-09 16:53:33 yum update 3 2017-10-09 16:53:33 ip a 4 2017-10-09 16:53:33 nslookup detik.com 5 2017-10-09 16:53:33 nmtui
Reference:
https://www.2daygeek.com/display-date-time-linux-bash-history-command/