I was looking through twittter recently and saw a good post on the bash history –
However I thought I would say how I use my Bash History…
Firstly a warning on using Bash (or most shells actually). Leave them properly! I was recently showing someone some tips on using Linux and I told him to have a look at his history. He didn’t have one. Why? Because once he was finished doing his changes he just closed the SSH client. He did not log out first. Although this will not break anything this is nasty, may leave processes lying around and will not leave a useful personal history. Be sensible and before just closing the SSH cliennt type
or hit CTRL + d.
Right back to the history. As the other post suggests apart from just looking at your history with “history” it is handy to look or a particular command. For example if you are looking for the last times you used the mount command run
history | grep mount
maybe you ran that a few days ago and it was a pretty easy command. What if you ran it six months ago and involved a lot of options?
The history goes back a long time so it maybe there but on a machine you use a lot maybe not. I would suggest therefore every so often creating a file with your history file so you can go back to it. Run
history > /home/user/info_install.txt
to create a file “info_install.txt” in your home directory (assuming /home/user/ is your home directory) with all your commands in it. Maybe you are migrating to a new server but want to keep a note of what you did. You really should document things properly but this is a start.
Create a file of your history regularly in different files and remember to copy them away. I often have a number of files and I often type echo “COMMENT” after something useful such as
apt install program
run program 2
service restart program
echo “Add config to /etc/program.cfg”
history > history_program.txt
Remenber that when you redirect output to a file > will overwrite whereas >> adds to a file.