Last active
May 14, 2024 00:50
-
-
Save petersenna/442f5f2ab97af65f24c0 to your computer and use it in GitHub Desktop.
Add this to your .bashrc to create a backup of your bash history every time you open a new terminal, but not more than one time per hour(find -mmin +60). This will backup your bash history if it has more lines than the backup file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export HISTSIZE="" | |
HIST_FILE=~/.bash_history | |
BACK_FILE=~/.bash_history_backup | |
if [ ! -f $BACK_FILE ];then touch -d "2 hours ago" $BACK_FILE;fi | |
if test $(find $BACK_FILE -mmin +60); then | |
HIST_SIZE=$(cat $HIST_FILE|wc -l) | |
BACK_SIZE=$(cat $BACK_FILE|wc -l) | |
GROWTH=$(($HIST_SIZE - $BACK_SIZE)) | |
if [ $GROWTH -lt 0 ];then | |
echo Looks like your bash history has problems... | |
echo You can restore with cp $BACK_FILE $HIST_FILE | |
else | |
cp $HIST_FILE $BACK_FILE | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment