< BACK
Bash tips, tricks and code snippets
Command line logging history
This source has an excellent tip for maintaining a log of bash commands.
Create a directory
mkdir ~/.logs/
then add the following to the ~/.bashrc
file:
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'
After logging out and in again the history logging will be active.
NOTE: directory ~/.logs/
must exist and be writable!