BASH HISTORY
From Indie IT Wiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
HOWTO: HISTORY:
Change Display Format - Add Time & Date
Edit your ~/.bashrc file... or system wide for all users /etc/bash.bashrc
# history format HISTTIMEFORMAT="%Y-%m-%d %H:%M:%S "
Reload:
source ~/.bashrc source /etc/bash.bashrc
Delete An Entry From History
Find the number next to the one you want to delete and run...
history -d $num
Log Commands Executed By All Users
Edit the /etc/bash.bashrc file and add this line...
sudo nano /etc/bash.bashrc PROMPT_COMMAND='history -a >(logger -t "$USER[$PWD] $SSH_CONNECTION")' or readonly PROMPT_COMMAND='history -a >(logger -t "$USER[$PWD] $SSH_CONNECTION")' or readonly PROMPT_COMMAND='history -a >(logger -p local2.info -t "$USER[$PWD] $SSH_CONNECTION")'
Thanks to Ashok Linux Tips
Prevent Command From Being Recorded In History
If you want to run a command without saving it in history, prepend it with an extra space.
prompt$ echo saved prompt$ echo not saved \ > # ^ extra space
For this to work you need either ignorespace or ignoreboth in HISTCONTROL. For example, run...
HISTCONTROL=ignorespace
To make this setting persistent, put it in your .bashrc.