bash for loop« an older post

Saving command line history

Snippet

Alan Schussman asks "Is there a word for when you have to reboot for software updates, but have a ton of terminal tabs with a month’s work of personal project history in them that maybe, just maybe I’ll need someday?"

To which I say, "Frustrating."

I have these two bash functions to save and find commands I've run (yes, I have a history going back a large number of years).

$ hsave to save history.
$ sg COMMAND to find how I ran that command before.

Add it to the ~/.bash_logout script, and the terminal's history should save when you close a terminal. I have a large history buffer. As such, I do have a lot of duplicate commands across multiple saved history files. Having 4 windows open all the time doesn't help with that overlapping history either.

function hsave(){
  history >> ~/work/projects/sweep/history-`date +'%Y%m%d%H%i%s'`$1.txt
}
 
function sg(){
  grep -ir $1 ~/work/projects/sweep
}

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.