Rants, Raves, and Rhetoric v4

Separating Bash Histories

Years ago, maybe 2011 based on the age of files, our Systems group moved our Linux home directories to a central system. My only real complaint about this move was finding anything I needed in my Bash history. See, I am terrible at remembering things and often make typos. It is easier to go back in my history to a prior command and either run it or modify that one and run. The same home directory across all these systems complicated things by co-mingling commands. I was able to find things. Just eventually. That seemed inefficient.

Eventually, this situation annoyed me to the point I decided to fix it. And the fix was so simple it is amazing that I did not immediately address it rather than suffering with it for a couple years. (Well, actually, we picked Desire2Learn before the change so 90% of my server responsibilities were on Windows. Only when I was promoted to a Technology Strategist and returned to majority work in Linux did it get annoying enough to address.)

The fix? Add hostname to the HISTFILE variable in .bash_profile.

export HISTFILE=”${HOME}/.bash_history.`hostname`”

Apparently I made the change back on December 18th. In the six months since, I have not noticed any oddities with the history. This morning I noticed that I have about twenty different host named history files of various sizes and dates.

Given the number of files, while writing this post, I decided to re-organize these into a directory. (An organized home directory is a happy home directory. Heh.)

export HISTFILE=”${HOME}/.bash_history/.bash_history.`hostname`”

Then I ran these.

mv .bash_history .bash_history.org
mkdir .bash_history
mv .bash_history.* .bash_history

Then I exited which dumped that session’s history into a file in the old location. I logged in again and used cat and the output redirect to append those new lines to the correct file in the new location.

Exited again and logged in again. And everything still looks good.


Posted

in

by

Tags:

Comments

One response to “Separating Bash Histories”

  1. […] post Separating Bash Histories appeared first on Rants, Raves, and Rhetoric […]

Leave a Reply