Bashrc
July 19, 2021
Bash History
Knowledge is power, and your bash history is prior knowledge. By default, only the last 1,000 commands are stored. So let's fix that!
# view your current settings
grep ^HIST ~/.bashrc
Let's set HISTSIZE and HISTFILESIZE to 100,000:
# back it up just in case
cp ~/.bashrc ~/.bashrc.bak
# replace the old values
sed -i -e 's/^\(HISTSIZE=\|HISTFILESIZE=\)[0-9]\+/\1100000/g' ~/.bashrc
# confirm what changed
diff ~/.bashrc ~/.bashrc.bak
The other thing I like to see is WHEN I ran a particular command. We can accomplish this simply by defining the HISTTIMEFORMAT
environment variable.
echo 'export HISTTIMEFORMAT="[%Y-%m-%d %H:%M:%S] "' >> ~/.bashrc
Have a look:
$ history | tail -1
545 [2021-07-19 10:38:22] history | tail -1
Beautiful.