Selectively remove command history of windows terminal
The command history in Windows Terminal is managed by whatever shell application you are using in it.
You don't mention which shell you are using, but here are a few possibilities:
-
If you are using WSL with the
bash
shell, thenhistory -c
clears the history for the current shell instance. Deleting the file~/.bash_history
will clear the save history from previous sessions. You can selectively remove an entry from the current session usinghistory -d <offset>
(usehistory
by itself to see the offset). -
If you are using WSL with the
fish
shell, thenhistory clear
both clears the current shell history and deletes past history.history delete ...
can be used to remove specific entries. Seeman history
underfish
for more info. -
If you are using WSL with
zsh
, it seems to be a little more complicated -- I'll just provide a link to a separate answer on that. -
If you are using PowerShell, then
Clear-History
may clear it for a particular session. But if you are using thepsreadline
module (which is a default on most recent PowerShell versions, you may need to press Alt+F7 instead. To clear the permanent history file, you'll need to find it withGet-PSReadlineOption | select -expand historysavepath
and then delete that file. -
If you are using the
CMD
shell (the "old" Windows/DOS compatible shell), then Alt+F7 is also what you would use. CMD does not permanently store a history file, so no need to delete one.
Note that this all refers to the command history. There is also the concept of the scrollback buffer in Windows Terminal. In PowerShell and most WSL/Linux shells, the clear
command will clear that.