Saving first n lines of history

Say you want to clear your .bash_history except for the first 25 lines. Try:

sed -i -e 26,500d .bash_history

I have a some frequently-used routines parked in the first few lines, and they kept getting overwritten by more recent commands.

I'd rather use .profile or other shell init / rc files to revive those 25 most needed commands at each login.

1 Like

in your .bash_profile (or .profile) you could do:

HISTFILESIZE= 
HISTSIZE=

to make your bash history unlimited; this way they won't be overwritten.

1 Like