I managed to truncate my bash history file to 500 entries by running a shell that didn't have any of my configuration (it was vanilla).
I realized this about 300 commands too late, but luckily I had a session open from before the truncate. history
in that session gives me my "deleted" history, but it's in this format:
449 05/07/21 02:04:03 ncdu
and the first 300 entries are the truncated file and not the original 300.
I figure the actual 300 entries must be stored somewhere. How do I obtain them? I only have the one session with the old history.
Additionally, I'd like to obtain the previous history in the following format, if possible:
#1635749826
ll
CodePudding user response:
history -a
will overwrite your bash history file with the history returned by the history
command for the current session.
You need to copy your current bash history, and can then append it to the original file.
It does not, however, bring back the first 500 entries.
Thanks to @markp-fuso for this solution.