9

I would like to selectively remove some of the history in Windows Terminal. History refers to the past commands typed into the Windows Terminal.

How can this be done?

I'm using Windows 10, Windows Terminal 1.8.1521.

1
  • 1
    As @NotTheDr01ds mentions, adding information about which shell (Powershell, bash, etc.) will help narrow the scope of the question. Commented Jul 14, 2021 at 11:58

3 Answers 3

13

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, then history -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 using history -d <offset> (use history by itself to see the offset).

  • If you are using WSL with the fish shell, then history clear both clears the current shell history and deletes past history. history delete ... can be used to remove specific entries. See man history under fish 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 the psreadline 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 with Get-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 will clear the whole history. CMD does not permanently store a history file, so there's probably no need to delete one item.

    However, if you would like to clean up individual entries anyway, you can open the history popup with F7, select an item using Up/Down, and press Delete to remove it.

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.

7

Here is the location of the text file that contains the history for the Windows Terminal.

%APPDATA%\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt

2
  • 1
    Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center. Commented Jun 7, 2024 at 16:52
  • Using bash in VScode in windows, this is the only working solution i found, Thank you! Commented Oct 30, 2024 at 15:00
0

In Windows terminal (Windows 10) with Powershell version 7.* this worked for me:

Set-PSReadLineOption -HistorySaveStyle SaveNothing

I ended up adding three functions to the profile file ($profile.AllUsersCurrentHost)

Functions:

function History-file {
  Write-Output (Get-PSReadLineOption).HistorySavePath
}

function History-Stop {
  Set-PSReadLineOption -HistorySaveStyle SaveNothing
}


function History-Save {
  Set-PSReadLineOption -HistorySaveStyle SaveIncrementally
}

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.