This file contains 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 HISTCONTROL=erasedumps | |
export HISTSIZE=100000 | |
shopt -s histappend |
However, sometimes you want to go back to your history file and see what commands you issued on a particular day .... one solution is to make a periodic backup with a timestamp using cron.
First, make a directory to put your files in, and make a script which is going to do the work:
This file contains 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
cd | |
touch backup_history.sh | |
mkdir history |
Open the shell script and copy the following inside
This file contains 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
nano backup_history.sh | |
DATE=$(date +"%Y%m%d%H%M") | |
cp ~/.bash_history ~/history/$DATE.log |
close, then in the terminal issue
This file contains 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
sudo nano /etc/crontab | |
#and copy the following | |
@hourly ~/./backup_history.sh |
admittedly hourly is a little excessive - go here is you are unfamiliar with cron scheduling definitions and modify as you see fit
No comments:
Post a Comment