Skip to main content
added 442 characters in body
Source Link
Gilles 'SO- stop being evil'
  • 865.9k
  • 205
  • 1.8k
  • 2.3k

To get an empty history, temporarily set HISTSIZEHISTSIZE to zero.

function erase_history { local HISTSIZE=0; } erase_history 

If you want to erase the new history from this shell instance but keep the old history that was loaded initially, empty the history as above then reload the saved history fc -R afterwards.

If you don't want the erase_history call to be recorded in the history, you can filter it out in the zshaddhistory hook.

function zshaddhistory_erase_history { [[ $1 != [[:space:]]#erase_history[[:space:]]# ]] } zshaddhistory_functions+=(zshaddhistory_erase_history) 

Deleting one specific history element (history -d NUM in bash) is another matter. I don't think there's a way other than:

  1. Save the history: fc -AI to append to the history file, or fc -WI to overwrite the history file, depending on your history sharing preferences.
  2. Edit the history file ($HISTFILE).
  3. Reload the history file: fc -R.

To get an empty history, temporarily set HISTSIZE to zero.

function erase_history { local HISTSIZE=0; } erase_history 

If you want to erase the new history from this shell instance but keep the old history that was loaded initially, empty the history as above then reload the saved history fc -R afterwards.


Deleting one specific history element (history -d NUM in bash) is another matter. I don't think there's a way other than:

  1. Save the history: fc -AI to append to the history file, or fc -WI to overwrite the history file, depending on your history sharing preferences.
  2. Edit the history file ($HISTFILE).
  3. Reload the history file: fc -R.

To get an empty history, temporarily set HISTSIZE to zero.

function erase_history { local HISTSIZE=0; } erase_history 

If you want to erase the new history from this shell instance but keep the old history that was loaded initially, empty the history as above then reload the saved history fc -R afterwards.

If you don't want the erase_history call to be recorded in the history, you can filter it out in the zshaddhistory hook.

function zshaddhistory_erase_history { [[ $1 != [[:space:]]#erase_history[[:space:]]# ]] } zshaddhistory_functions+=(zshaddhistory_erase_history) 

Deleting one specific history element (history -d NUM in bash) is another matter. I don't think there's a way other than:

  1. Save the history: fc -AI to append to the history file, or fc -WI to overwrite the history file, depending on your history sharing preferences.
  2. Edit the history file ($HISTFILE).
  3. Reload the history file: fc -R.
setting HISTSIZE=0 locally is enough (thanks Isaac)
Source Link
Gilles 'SO- stop being evil'
  • 865.9k
  • 205
  • 1.8k
  • 2.3k

To get an empty history, temporarily set HISTSIZE to zero.

save_HISTSIZE=$HISTSIZE;function HISTSIZE=0;erase_history HISTSIZE=$save_HISTSIZE;{ unsetlocal save_HISTSIZEHISTSIZE=0; } erase_history 

If you want to erase the new history from this shell instance but keep the old history that was loaded initially, empty the history as above then reload the saved history fc -R afterwards.


Deleting one specific history element (history -d NUM in bash) is another matter. I don't think there's a way other than:

  1. Save the history: fc -AI to append to the history file, or fc -WI to overwrite the history file, depending on your history sharing preferences.
  2. Edit the history file ($HISTFILE).
  3. Reload the history file: fc -R.

To get an empty history, temporarily set HISTSIZE to zero.

save_HISTSIZE=$HISTSIZE; HISTSIZE=0; HISTSIZE=$save_HISTSIZE; unset save_HISTSIZE 

If you want to erase the new history from this shell instance but keep the old history that was loaded initially, empty the history as above then reload the saved history fc -R afterwards.


Deleting one specific history element (history -d NUM in bash) is another matter. I don't think there's a way other than:

  1. Save the history: fc -AI to append to the history file, or fc -WI to overwrite the history file, depending on your history sharing preferences.
  2. Edit the history file ($HISTFILE).
  3. Reload the history file: fc -R.

To get an empty history, temporarily set HISTSIZE to zero.

function erase_history { local HISTSIZE=0; } erase_history 

If you want to erase the new history from this shell instance but keep the old history that was loaded initially, empty the history as above then reload the saved history fc -R afterwards.


Deleting one specific history element (history -d NUM in bash) is another matter. I don't think there's a way other than:

  1. Save the history: fc -AI to append to the history file, or fc -WI to overwrite the history file, depending on your history sharing preferences.
  2. Edit the history file ($HISTFILE).
  3. Reload the history file: fc -R.
added 102 characters in body
Source Link
Gilles 'SO- stop being evil'
  • 865.9k
  • 205
  • 1.8k
  • 2.3k

You can erase the current unsaved history and reload the saved history:

fc -R 

To get an empty history, temporarily set HISTSIZE to zero.

save_HISTSIZE=$HISTSIZE; HISTSIZE=0; HISTSIZE=$save_HISTSIZE; unset save_HISTSIZE 

If you want to erase the new history from this shell instance but keep the old history that was loaded initially, empty the history as above then reload the saved history fc -R afterwards.


Deleting one specific history element (history -d NUM in bash) is another matter. I don't think there's a way other than:

  1. Save the history: fc -AI to append to the history file, or fc -WI to overwrite the history file, depending on your history sharing preferences.
  2. Edit the history file ($HISTFILE).
  3. Reload the history file: fc -R.

You can erase the current unsaved history and reload the saved history:

fc -R 

To get an empty history, temporarily set HISTSIZE to zero.

save_HISTSIZE=$HISTSIZE; HISTSIZE=0; HISTSIZE=$save_HISTSIZE; unset save_HISTSIZE 

Deleting one specific history element (history -d NUM in bash) is another matter. I don't think there's a way other than:

  1. Save the history: fc -AI to append to the history file, or fc -WI to overwrite the history file, depending on your history sharing preferences.
  2. Edit the history file ($HISTFILE).
  3. Reload the history file: fc -R.

To get an empty history, temporarily set HISTSIZE to zero.

save_HISTSIZE=$HISTSIZE; HISTSIZE=0; HISTSIZE=$save_HISTSIZE; unset save_HISTSIZE 

If you want to erase the new history from this shell instance but keep the old history that was loaded initially, empty the history as above then reload the saved history fc -R afterwards.


Deleting one specific history element (history -d NUM in bash) is another matter. I don't think there's a way other than:

  1. Save the history: fc -AI to append to the history file, or fc -WI to overwrite the history file, depending on your history sharing preferences.
  2. Edit the history file ($HISTFILE).
  3. Reload the history file: fc -R.
Source Link
Gilles 'SO- stop being evil'
  • 865.9k
  • 205
  • 1.8k
  • 2.3k
Loading