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.

The post Separating Bash Histories appeared first on Rants, Raves, and Rhetoric v4.

From Separating Bash Histories published May 28, 2015 at 10:40AM.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s