4 ms·
Something that has been serving me well over the years: export PROMPT_COMMAND='if [ "$(id -u)" -ne 0 ]; then echo "$(date "+%Y-%m-%d.%H:%M:%S") $(pwd) $(histor
by BhavdeepSethi 10y ago
Something that has been serving me well over the years:
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.
- jcsalterego 10y agoNice!
- ball_of_lint 10y agoI do the same thing, and have a couple of commands set up to run grep over the last day, week, month, or ever in my history. I don't use my full history every day, but it's something worth keeping around.
- cbcoutinho 10y agoI'm still new to bash scripting - how do you use this? Just put into ~/.profile and create a cron job for $PROMPT_COMMAND?
- amelius 10y agoJust put it in ~/.bashrc And run mkdir ~/.logs because that's where the logs are stored.
- BhavdeepSethi 10y agoJust add it to your ~/.bash_profile or ~/.bashrc (source it or restart your terminal). PROMPT_COMMAND: http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x264.html http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x264.html 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.
- bm1362 10y agoTo preserve your existing prompt, you can append it using +=: 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'
- corpMaverick 10y agoI have this exact line too. Author unknown.