TL;DR: If your history begins to truncate (e.g., your
HISTSIZE is 400 but your history number is 500), resetting your history with
history -c will clear
HISTSIZE or fewer lines from your history, and subtract that many from your history number, but will not reset it to 0 (in the example, it would reset it to 100). How can I completely reset the history number back to 0?
Bash 4.2 (and also on 4.4). I want my history numbers to be under 4 digits. relevant bashrc sections:
HISTSIZE=99 HISTFILESIZE=100 #ignores back-to-back duplicate commands, not those that start with a space HISTCONTROL=ignoredups #ignore commands fewer than 5 characters long because we can type those HISTIGNORE="?:??:???:????:?????:history"
the history number as seen with
\! in the PS1 will obviously go beyond these values. I want to be able to reset the history number down to ~100 when it goes above 1,000.
history -c clears the terminal history, but that only reduces the history number by the amount of commands that it cleared, e.g.:
j:~$ history | wc -l 99 j:~$ echo $HISTFILESIZE 100 j:~$ echo $HISTCMD 1203 j:~$ history -c j:~$ echo $HISTCMD 1106
So... how do I drop the history number down to a smaller number, such as
$HIST(FILE)SIZE. This is in a tmux session, but I don't think that should matter.
Aside: is there a method to get the current history number as a variable that requires fewer pipes than the one I'm currently using? EDIT: as Jeff mentioned,
$HISTCMD stores this value.
None of the solutions provided work. Here's what they do with