4 ms·
Just put: export PROMPT_COMMAND='if [ "$(id -u)" -ne 0 ]; then echo "$(date "+%Y-%m-%d.%H:%M:%S") $(pwd) $(history 1)" >> "${HOME}/bash_logs_$(hostname)/bash-h
by rhaps0dy 6y ago
Just put:
export PROMPT_COMMAND='if [ "$(id -u)" -ne 0 ]; then echo "$(date "+%Y-%m-%d.%H:%M:%S") $(pwd) $(history 1)" >> "${HOME}/bash_logs_$(hostname)/bash-history-$(date "+%Y-%m-%d").log"; fi'
in your ~/.bash_profile. You also may need to `mkdir "${HOME}/bash_logs_$(hostname)"`
I took this command from a Hacker News thread of the past. I don't have a link to it any more.
- vardump 6y agoThere are several past posts with same bash one liner. For example https://news.ycombinator.com/item?id=14108671 https://news.ycombinator.com/item?id=14108671