Last active
January 3, 2023 09:52
-
-
Save patientzero/39496387237d85c8d29d209d29957f52 to your computer and use it in GitHub Desktop.
regular backup of bash_history
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
#!/bin/bash | |
# This is a script to backup your command history. | |
# How to use: | |
# 1.) create dir (mkdir ~/history) and place this script as backup_hist.sh in it. | |
# 2.) add daily cronjob | |
# to run daily at midnight, add this line to the crontab(crontab -e): | |
# 0 0 * * * /bin/bash ~/history/backup_hist.sh > /dev/null 2>&1 | |
# 3.) To allow filtering of commands by date, add this to your .bashrc: | |
# HISTTIMEFORMAT="%d/%m/%y %T " and also here: | |
# hist command in non interactive shells by defautl disabled, so enable by adding historyfile | |
HISTTIMEFORMAT="%d/%m/%y %T " | |
HISTFILE=~/.bash_history | |
set -o history | |
yesterday="date -d yesterday +%d/%m/%y" | |
history | grep $($yesterday) > /PATH_TO_HISTORY_BACKUP/$(date -d "yesterday" +%d-%m-%y)_history | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Helpful configuration(put in .bashrc) to use same history file over all sessions and add a timestamp to the history: