WSL (Windows Subsystem for Linux) does not keep one universal command history. Your Linux shell—such as Bash, Zsh, or Fish—usually saves commands in a history file for each Linux user, while the terminal may separately retain visible scrollback. PowerShell history is separate again. To clear WSL history, first decide which of these you mean, then clear the right source.
This guide explains how to clear Bash history, remove a single command, handle other shells and WSL distributions, and clear terminal scrollback. It also covers what clearing history does—and does not—do for privacy.
What “WSL History” Can Mean
When people ask how to clear WSL history, they may be referring to different kinds of records:
- Linux shell history: Commands saved by Bash, Zsh, Fish, or another shell, usually in a file in your Linux home directory.
- Current-session history: Commands the shell can still show with its history command before the session ends.
- Terminal scrollback: Text still visible when you scroll up in Windows Terminal or another terminal app. This is not the same as the shell’s saved history.
- PowerShell history: Commands entered at a Windows PowerShell prompt. Clearing Linux shell history does not clear this history.
Most WSL users run Bash, so the Bash instructions below are a good starting point. If you are unsure which shell is open, run echo $SHELL in WSL. The result commonly includes bash, zsh, or fish.
How to Clear Bash History in WSL
For Bash, clear the in-memory history and write the empty list to its history file with these commands:
history -c
history -w
history -c clears the history list for the current Bash session. history -w writes that list to the file named by Bash’s HISTFILE setting, which is usually ~/.bash_history. Running both commands clears the current session’s list and updates the usual saved history file.
To check the result, run history. It should not display the older commands from that shell session. You can also check whether the standard history file is empty:
wc -l ~/.bash_history
A result of 0 means that file currently has no lines. If the file does not exist, Bash may not have saved history there yet, or your shell may use a different history file.
One important detail: other open Bash sessions can still have old commands in memory. When one of those sessions closes, it may write its history back to the file. For the most reliable result, clear history in each open WSL shell, or close other sessions before clearing it. Then open a fresh WSL session and check again.
Clear the Bash History File Directly
You can empty the standard Bash history file directly, too. In your WSL shell, run:
: > ~/.bash_history
This truncates the file without deleting it. Alternatively, remove the file with rm ~/.bash_history; Bash can create it again later. If you choose either method while other Bash sessions are open, those sessions may still write older commands back to the file when they exit. Clear or close those sessions as well.
For an ordinary cleanup, the built-in Bash commands are generally more convenient:
history -c
history -w
Use direct file editing when you specifically want to empty the saved file. Avoid using sudo unless you are intentionally clearing history for the root account: your normal user’s history and root’s history are separate.
How to Delete One Command from WSL History
If you only want to remove a particular command, you do not need to erase the entire history. First display the list and identify the number beside the entry:
history
Then delete that numbered entry and save the updated history:
history -d 123
history -w
Replace 123 with the number shown beside the command you want to remove. History numbers are specific to the list in your current shell, so check the number immediately before deleting it. If the command appears more than once, remove each matching entry you want gone.
Be aware that a command can be recorded in another open session or another shell’s history file. If you are cleaning up sensitive information, inspect the relevant sessions and history files rather than assuming one deletion removes every copy.
Clear History in Zsh or Fish
The Bash commands are not universal. Zsh and Fish use different history systems, so do not assume that history -c will behave the same way in every shell.
For Zsh, the saved history file is commonly ~/.zsh_history. To remove its saved contents, you can truncate that file:
: > ~/.zsh_history
Close other Zsh sessions first, or clear their history too, because an open session may save older entries later. Zsh settings can change the history-file location, so check the HISTFILE variable if that path is not present:
echo $HISTFILE
For Fish, use its history command to clear saved history:
history clear
Check the documentation for your installed shell version if its behavior differs, and confirm the result in a new session. The history location and settings can vary, especially if you have customized your shell configuration.
Clear Terminal Scrollback in Windows Terminal
Clearing shell history does not necessarily erase the text you can still see by scrolling upward in your terminal window. That visible text is terminal scrollback. Conversely, clearing the screen does not necessarily erase the history file.
In a Linux shell, clear clears the visible screen, but it may leave scrollback available. Windows Terminal provides a separate action for clearing the buffer. Open its command palette with Ctrl+Shift+P, search for Clear buffer, and select the matching action if it is available in your version. You can also review Windows Terminal’s keyboard-shortcut settings for a configured clear-buffer shortcut.
Other terminal applications may use different menus or shortcuts. Clearing the buffer affects what the terminal displays; it does not clear Bash, Zsh, or Fish history. For a more complete cleanup, handle both the shell history and the terminal scrollback.
Clear PowerShell History Separately
If you ran commands at a PowerShell prompt in Windows, those commands are not part of your Linux shell history. PowerShell’s interactive history is managed separately, often by the PSReadLine module. In PowerShell, you can clear the current session’s history with:
Clear-History
That command may not remove the persistent PSReadLine history file. Its location and behavior depend on your PowerShell and PSReadLine setup. To inspect PSReadLine’s history-file path, run:
(Get-PSReadLineOption).HistorySavePath
If you need to remove saved PowerShell history, close PowerShell sessions that could write to it, then carefully inspect the path before deleting or emptying the file. Do not run Linux history commands in PowerShell and expect them to clear Windows command history.
Clear History for Another WSL Distribution or User
Each WSL distribution has its own Linux filesystem, and each Linux user typically has a separate home directory. Clearing ~/.bash_history in Ubuntu does not automatically clear history in Debian, another distribution, or another user account.
To see installed distributions from PowerShell or Command Prompt, run:
wsl --list --verbose
Open the distribution you want to clean, then repeat the shell-specific steps as the relevant Linux user. To launch a named distribution, for example:
wsl -d Ubuntu
If the history belongs to another Linux account, sign in as that account and clear its history there. Be cautious with root: commands run as root may be recorded separately from commands run as your everyday user. A distribution reset or removal is not necessary just to clear shell history, and it can destroy much more than command records.
Common Problems When Clearing WSL History
- Old commands return after reopening WSL: Another shell session may have written its in-memory history back to the file. Clear or close other sessions, then check again.
-
The history file appears empty, but commands still show: The current shell may still hold commands in memory. In Bash, run
history -cand thenhistory -w. - Nothing changes when you use a Bash command: Confirm which shell is running. Zsh, Fish, and PowerShell use different history mechanisms.
- You cleared Ubuntu, but another distro still shows commands: WSL distributions have separate filesystems and histories. Repeat the cleanup in each distribution you use.
- You can still see commands by scrolling upward: Clear the terminal’s scrollback separately. The shell’s saved history and the terminal display are different things.
Does Clearing WSL History Securely Erase Commands?
Clearing a shell history file is useful for removing commands from normal history listings, but it is not a guarantee of secure erasure. Depending on your system and configuration, command text may also remain in backups, filesystem snapshots, logs, copied terminal output, or other shell sessions. Simply deleting a file may not overwrite the underlying storage.
It is best not to type passwords, access tokens, or other secrets directly into commands. They may be saved in history or exposed through other system records. If a secret was entered into a command, clearing history is not a substitute for changing or revoking that secret. Also remember that shell settings can control whether commands are saved, which commands are ignored, or where history is stored.
For routine privacy on a personal WSL setup, clearing the appropriate shell history and terminal buffer is usually enough. For sensitive data, treat the history cleanup as one step in a broader security response rather than as proof that no copy remains.
Conclusion
To clear standard Bash history in WSL, run history -c followed by history -w. Clear other open Bash sessions too, since they may restore old entries. If you use Zsh or Fish, follow that shell’s history method; if you mean visible terminal text or PowerShell commands, clear those separately. Finally, remember that WSL distributions and Linux users keep separate histories, and clearing a history file does not securely erase every possible copy of a command.
Disclaimer: Articles are written by Humans, AI or Both. Verify Important information.