Delete command from the history? #17509

Closed
opened 2026-01-31 05:44:37 +00:00 by claunia · 6 comments
Owner

Originally created by @Suncatcher on GitHub (May 18, 2022).

Description of the new feature/enhancement

Sometime we need to clean out unnecessary commands from the history, but keep all the rest, so it shouldn't be a total history wipe.

Proposed technical implementation details (optional)

In *nix we have a very nice and nifty command that does exactly that:

history -d linenumber

We should have the same capability in Windows Terminal as well.

Originally created by @Suncatcher on GitHub (May 18, 2022). <!-- 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 I ACKNOWLEDGE THE FOLLOWING BEFORE PROCEEDING: 1. If I delete this entire template and go my own path, the core team may close my issue without further explanation or engagement. 2. If I list multiple bugs/concerns in this one issue, the core team may close my issue without further explanation or engagement. 3. If I write an issue that has many duplicates, the core team may close my issue without further explanation or engagement (and without necessarily spending time to find the exact duplicate ID number). 4. If I leave the title incomplete when filing the issue, the core team may close my issue without further explanation or engagement. 5. If I file something completely blank in the body, the core team may close my issue without further explanation or engagement. All good? Then proceed! --> # Description of the new feature/enhancement Sometime we need to clean out unnecessary commands from the history, but keep all the rest, so it shouldn't be a total history wipe. <!-- A clear and concise description of what the problem is that the new feature would solve. Describe why and how a user would use this new functionality (if applicable). --> # Proposed technical implementation details (optional) <!-- A clear and concise description of what you want to happen. --> In *nix we have a very nice and nifty command that does exactly that: history -d linenumber We should have the same capability in Windows Terminal as well.
claunia added the Issue-FeatureNeeds-TriageNeeds-Tag-FixNeeds-Attention labels 2026-01-31 05:44:37 +00:00
Author
Owner

@zadjii-msft commented on GitHub (May 18, 2022):

Commandline history is something that is largely driven on a per-shell basis. Which shell are you using? cmd? powershell/?

I bet that PowerShell already has a similar feature. cmd probably not as much, though there is GetConsoleHistoryInfo/SetConsoleHistoryInfo, which I'm sure doskey can modify in a more user friendly way.

@zadjii-msft commented on GitHub (May 18, 2022): Commandline history is something that is largely driven on a per-shell basis. Which shell are you using? `cmd`? `powershell`/? I bet that PowerShell already has a similar feature. `cmd` probably not as much, though there is `GetConsoleHistoryInfo`/`SetConsoleHistoryInfo`, which I'm sure `doskey` can modify in a more user friendly way.
Author
Owner

@Suncatcher commented on GitHub (May 18, 2022):

Which shell are you using? cmd? powershell?

PS 7.2.3.

I believe cmd has no history capability, so it is pretty irrelevant for this feature request. Unless of course Windows Terminal adds own history on top of cmd

@Suncatcher commented on GitHub (May 18, 2022): > Which shell are you using? cmd? powershell? PS 7.2.3. I believe `cmd` has no history capability, so it is pretty irrelevant for this feature request. Unless of course Windows Terminal adds own history on top of `cmd`
Author
Owner

@Suncatcher commented on GitHub (May 18, 2022):

I bet that PowerShell already has a similar feature

Yes it already has. It is Clear-History -ID 12, 20 cmdlet. But I observe it behaves weird on the Terminal. Example:

image

I use Get-History cmdlet to get the commands IDs. but it fetches me the history only of current terminal session, however by arrow keys I can access all commands from the past. How to access all IDs?

@Suncatcher commented on GitHub (May 18, 2022): > I bet that PowerShell already has a similar feature Yes it already has. It is `Clear-History -ID 12, 20` cmdlet. But I observe it behaves weird on the Terminal. Example: ![image](https://user-images.githubusercontent.com/6388034/169035300-ee60bccd-bc8d-4f08-9c90-c0dd2bbdc6d9.png) I use Get-History cmdlet to get the commands IDs. but it fetches me the history only of **current terminal session**, however by arrow keys I can access all commands from the past. How to access all IDs?
Author
Owner

@237dmitry commented on GitHub (May 18, 2022):

For current command history list:

help Clear-History

And you can empty or delete $env:AppData\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt

@237dmitry commented on GitHub (May 18, 2022): For current command history list: ``` help Clear-History ``` And you can empty or delete `$env:AppData\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt`
Author
Owner

@Suncatcher commented on GitHub (May 18, 2022):

And you can empty or delete $env:AppData\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt

thanks, that worked. I'm closing this ticket, but hotkey for this would be much more convenient than editing this file.

@Suncatcher commented on GitHub (May 18, 2022): > And you can empty or delete $env:AppData\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt thanks, that worked. I'm closing this ticket, but hotkey for this would be much more convenient than editing this file.
Author
Owner

@DHowett commented on GitHub (May 18, 2022):

hotkey for this would be much more convenient than editing this file

Agreed! That is a request you should file on https://github.com/PowerShell/PSReadLine, though, as they control the storage and manipulation of history in PowerShell.

@DHowett commented on GitHub (May 18, 2022): > hotkey for this would be much more convenient than editing this file Agreed! That is a request you should file on https://github.com/PowerShell/PSReadLine, though, as they control the storage and manipulation of history in PowerShell.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#17509