Last active
August 5, 2021 11:04
-
-
Save ArnauMontagud/7e84085b6d6c371881b3b93f68cae982 to your computer and use it in GitHub Desktop.
[Shell Infinite bash history] Keep all history, forever #shell #bashrc
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
# Option 1, from here: https://spin.atomicobject.com/2016/05/28/log-bash-history/ | |
# more history settings, date wise, infinite | |
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' | |
Add to ~/.bashrc, Make the ~/.logs folder, and you are set forever | |
Then, you can do a grep 'whatever script or data name' ~/.logs/* | |
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
#!/usr/bin/env bash | |
# Option 2, from here: https://gist.github.com/andrew-hardin/a522fb1739ed052d146c4c5d3bc5052c (that comes from here: http://stackoverflow.com/questions/9457233/unlimited-bash-history) | |
# Eternal bash history | |
# -------------------- | |
# Undocumented(?) feature which sets the size to "unlimited". | |
# http://stackoverflow.com/questions/9457233/unlimited-bash-history | |
export HISTFILESIZE= | |
export HISTSIZE= | |
export HISTTIMEFORMAT="[%F %T] " | |
# Change the file location because certain bash sessions truncate .bash_history file upon close. | |
# http://superuser.com/questions/575479/bash-history-truncated-to-500-lines-on-each-login | |
export HISTFILE=~/.infinite_history | |
# Force prompt to write history after every command. | |
# Useful when using multiple terminals spread between programs | |
# or machines with network shared home directory. | |
# http://superuser.com/questions/20900/bash-history-loss | |
export PROMPT_COMMAND="history -a; $PROMPT_COMMAND" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment