log bash history to an sqlite database
Recent is a more structured way to log your bash history.
The standard ~/.bash_history file is inadequate in many ways, its worst fault is to by default log only 500 history entries, with no timestamp. You can alter your bash HISTFILESIZE and HISTTIMEFORMAT variables but it is still a unstructured format with limited querying ability.
Recent does the following:
- Logs current localtime, command text, current pid, command return value, working directory to an sqlite database in ~/.recent.db.
- Logs history immediately, rather than at the close of the session.
- Provides a command called recent for searching logs.
You need will need sqlite installed.
Install the recent pip package:
pip install recent
Add the following to your .bashrc or .bash_profile:
export PROMPT_COMMAND='log-recent -r $? -c "$(HISTTIMEFORMAT= history 1)" -p $$'
And start a new shell.
Look at your current history using recent:
Search for a pattern as follows:
For more information see the help:
Not currently recent doesn’t integrate with bash commands such as Ctrl-R, but this is in the pipeline.
You can directly query your history using the following:
sqlite3 ~/.recent.db "select * from commands limit 10"
dev installation instructions
git clone https://github.com/trengrj/recent && cd recent
pip install -e .
Please note, recent does not take into account enforcing logging for security purposes. For this functionality on linux, have a look at auditd http://people.redhat.com/sgrubb/audit/.
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, Size & Hash SHA256 Hash Help||File Type||Python Version||Upload Date|
(6.6 kB) Copy SHA256 Hash SHA256
|Wheel||py2.py3||Jul 3, 2017|
(4.7 kB) Copy SHA256 Hash SHA256
|Source||None||Jul 3, 2017|