How To Add Date and Time To Bash History

As Linux users and engineers, we often have to look back in our bash history to figure out exactly where things went wrong. The worst is when you execute the `history` command and all you get is a list of the commands you ran without the date/time of the command execution included. 


Thankfully, there's an easy solution. Simply run the following command which defines the `HISTTIMEFORMAT` environment variable and exports that environment variable whenever you login/establish a new shell. 

```

echo 'export HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bash_profile

```

Where:

%d – Day

%m – Month

%y – Year

%T – Time

 

After executing the command, run `source ~/.bash_profile` or close your bash shell and open a new one.

  • 0 Usuários acharam útil
Esta resposta lhe foi útil?

Artigos Relacionados

Expand your bash history to 2500

Expand your .bash_history to 2500 I do alot of testing and alot of work on Centos servers. I...

CentOS One Liner Commands

Centos Oneliners kill all pts for x in $(ps aux | grep pts| awk '{print $2}'); do kill...

Setup a SSH Tunnel for Secure Browsing

Setup a SSH Tunnel to Secure your Browsing on a Public Network Have you been sitting at your...

How to Optimize/Repair a Table (MySQL)

How to Optimize and Repair your MySQL Tables Does your database feel like it has slowed down?...

Setup logrotate to rotate your logs

Use logrotate to Manage Log Fiiles logrotate is a tool for managing log files created by...