If you are not using any third party variants of bash like oh-my-bash,
put the following command in your .bashrc
:
export PROMPT_COMMAND='if [ "$(id -u)" -ne 0 ]; then echo "$(date "+%Y-%m-%d.%H:%M:%S") $(pwd) $(history 1)" >> ~/.logs/bash-history-$(date "+%Y-%m-%d").log; fi'
Close bashrc and open new terminal. Now, your history are saved in the folder ~/.logs
according to timestamp.
Example file
/home/paradox/.logs/bash-history-2018-12-15.log
/home/paradox/.logs/bash-history-2018-12-16.log
/home/paradox/.logs/bash-history-2019-01-19.log
Now, if you are using oh-my bash, you have to put the above command in the function that creates prompt_command.
This is according to the type of theme you are using. The prompt command is generated in the function __powerline_prompt_command
.
For me, I am using powerline theme. So, I have to put my logger command in powerline-base.sh
file inside the function I have written above.
function __powerline_prompt_command {
if [ "$(id -u)" -ne 0 ]; then
echo "$(date "+%Y-%m-%d.%H:%M:%S") $(pwd) $(history 1)" >> ~/.logs/bash-history-$(date "+%Y-%m-%d").log
fi
...
...