by BhavdeepSethi · 9y ago · 0 comments
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'
Creates a daily log file of every command entered. Searching for anything is a simple grep command.
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'Nope, no cron. It basically takes your command, and appends (creates if it does not exist) it to a file based on the current date.
And run
mkdir ~/.logs
because that's where the logs are stored.