Normally, history only echo the sequence number and command to your console like:

501 ps -ef
502 df -h
503 htop
etc...
etc... 

You cannot see the timestamp and user at all. How can we add these 2 information types to the history?
Simply add 4 extra lines to the ~/.bashrc file (root) and reload the source when you need to see the results. I added 2 extra lines in order to expand the history size.

vi ~/.bashrc

HISTSIZE=2000 
HISTFILESIZE=5000
HISTUSER=`who smells bad | awk '{print $1}'`
HISTTIMEFORMAT="($HISTUSER) %F %T "

After these commands ( yes, “who smells bad” is an actual command to reveal the logged-in username and not the sudo user “root”), reload bash with this command:

source ~/.bashrc 

After a while, history will be filled with timestamps and usernames.

  610  (angioni) 2024-09-02 12:15:44 who smells bad
  611  (angioni) 2024-09-02 12:19:15 who smells bad | awk '{print $1}'
  612  (angioni) 2024-09-02 12:19:41 vi ~/.bashrc
  613  (angioni) 2024-09-02 12:22:34 source ~/.bashrc
  614  (angioni) 2024-09-02 12:22:37 history
  615  (angioni) 2024-09-02 12:23:01 cat ~/.bashrc
  616  (angioni) 2024-09-02 12:26:01 set | grep -i HIST
  617  (angioni) 2024-09-02 12:26:36 history

Linux Rules

Views: 71

By angioni

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.