Is there any way I can see at what time the commands were executed from the bash history? We can see the order but is there any way I can get the time also?
Bottom-Line: Execution time in the Bash history
Is there any way I can see at what time the commands were executed from the bash history? We can see the order but is there any way I can get the time also?
Bottom-Line: Execution time in the Bash history
Press Ctrl+Alt+T to open a terminal, then run one of the commands below:
To make the change permanent for the current user run:
To test the effects run:
For more info see man bash or An A-Z Index of the Bash command line for Linux.
For commands that were run before
HISTTIMEFORMAT
was set, the current time will be saved as the timestamp. Commands run afterHISTTIMEFORMAT
was set will have the proper timestamp saved.Open terminalCtrl+Alt+T and run,
then,
To make the changes permanent follow the below steps,
you need to add the below line to .bashrc file and then save it,
run the below command to source .bashrc file,
After that run
history
command.source:http://www.cyberciti.biz/faq/unix-linux-bash-history-display-date-time/
Yes, you can: if you set
$HISTTIMEFORMAT
, the.bash-history
will be properly timestamped. That doesn't help with existing.bash-history
content, but will help in the future.Changing
HISTIMEFORMAT
didn't work for me, because I'm using zsh.If you want to make it work with zsh, you just have to type :
history -i
You 'll see changes on next login.
My version that works
ref. https://www.linuxuprising.com/2019/07/bash-history-how-to-show-timestamp-when.html
E.g.
View full syntax for
HISTTIMEFORMAT
hereTo enable history timestamps for all users, create a script in /etc/profile.d :
I know, I'm answering it very late, but to do this for all the users, you can create any
.sh
file in/etc/profile.d
and add the following line to it:If you not logged in as
root
or superuser, you need to use thetee
command to do this:If you want to append to any existing file, pass
-a
flag totee
command:I maintain a history per tty device per user, in .bash_profile, and let them grow large. Sometimes I want to find where a command was used across all those files using grep, say. I have just spent a while getting how I want, with time stamps as strings and headers for each file plus which tty before the time so if I am grepping I will see where and when used:
Can't go into all the background as life is too short (LITS) but here are my dev notes as I worked it up. This is on macOS so no special gawk but I do use date -r where it may differ for you, date -d?. Enjoy! :