Bash keeps command history in two places: the current shell’s in-memory list and, usually, the ~/.bash_history file. To clear both from the current shell, run history -c followed by history -w. To stop that shell from saving history when it exits, run unset HISTFILE. These actions affect different parts of history, so choose the steps that match what you want to remove or prevent.
Choose the right Bash history action
| Goal | Command or setting | What it affects |
|---|---|---|
| Clear the current shell’s history list | history -c |
Clears the in-memory list; it does not by itself overwrite the history file. |
| Clear the saved history file using the current list | history -c, then history -w |
Writes the now-empty list to the history file, replacing its contents. |
| Remove particular entries | history -d OFFSET or history -d START-END |
Deletes selected entries from the current list; write the modified list to update the file. |
| Prevent this shell from saving history at exit | unset HISTFILE |
Disables saving by this shell when it exits; it does not erase an existing file. |
| Keep no commands in the in-memory list | HISTSIZE=0 |
Controls list retention; it does not by itself remove an existing history file. |
| Skip selected commands | HISTCONTROL=ignorespace or ignoreboth |
Filters some new commands rather than disabling history altogether. |
Clear the current list and the history file
In the Bash session you want to clear, run:
history -c
history -w
history -c clears that shell’s in-memory list. history -w then writes the list to the history file, replacing its contents. Bash’s default history file is ~/.bash_history, though the path can be changed with HISTFILE. The Bash Reference Manual documents history -c and history -w in its history builtins section and the default file in Bash variables.
If HISTFILE is unset or empty, history -w has no file to write. Check or set the intended history-file path before writing if needed. For example, to use the default path explicitly, run HISTFILE="$HOME/.bash_history" before the two history commands.
Account for other open Bash sessions
Each running interactive Bash shell can have its own history list. A different shell may still hold old entries and write them when it exits, so clearing one session does not guarantee that the file will remain empty. Bash normally saves history on exit; with the histappend option enabled, it appends rather than overwrites. Close or manage other relevant shells before relying on a cleared file. See the manual’s Bash history facilities for the save behavior and histappend.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →#1 Best Overall
- Used Book in Good Condition
Delete one command or a range of entries
Display the current list with history, then use the entry number shown to identify what to remove. For one entry:
history -d OFFSET
For an inclusive range of entries:
history -d START-END
Replace OFFSET, START, and END with the relevant positions. Check the displayed list carefully before deleting: history numbering can shift as entries are removed. The builtin also accepts negative positions counted back from the end of the list. To make the change persist in the history file, run history -w after deleting. This updates the file from the current shell’s list, so another open shell can still later write its own history.
Stop Bash from saving history when a shell exits
For the current Bash session, run:
unset HISTFILE
GNU Bash documents: “If HISTFILE is unset or null, the shell does not save the command history when it exits.” This prevents that shell from saving history at exit; it does not delete history already stored in a file or erase the in-memory list. To apply the setting to future interactive Bash sessions, add it to the startup configuration that those sessions actually read. Which startup file applies depends on how Bash is launched and the user’s environment; there is no single file that is correct for every setup.
Prevent commands from being retained or selectively recorded
Keep no entries in the in-memory list
Set HISTSIZE to zero in the current shell:
HISTSIZE=0
This prevents commands from being retained in Bash’s in-memory history list. It is separate from HISTFILE, which controls saving the list to a file when the shell exits, and it does not remove an existing file.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallCrashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteSkip commands that begin with a space
If HISTCONTROL is set to ignorespace, Bash omits commands whose first character is a space. Set it for the current shell with:
HISTCONTROL=ignorespace
ignoreboth combines that behavior with ignoring immediately repeated commands:
Rank #4
HISTCONTROL=ignoreboth
These are selective filters, not full history shutdown. A leading space has no such effect unless the applicable history settings enable it; other settings, including HISTIGNORE, can also affect which commands are recorded. For details, see the Bash manual’s history-related variables.
Make the setting apply to later shells
Commands entered at the prompt affect the current shell. To keep a setting for later interactive shells, put the appropriate assignment or unset HISTFILE command in the startup configuration those shells read. Because Bash’s startup behavior depends on whether it is interactive, a login shell, or launched by a particular terminal or service, confirm which configuration file your setup uses rather than assuming one universal location.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Best Value
For an ongoing policy, distinguish the desired behavior: use HISTFILE to control saving to disk, HISTSIZE to control the in-memory list, and HISTCONTROL for selective filtering. None of these retroactively clears a pre-existing history file; clear that separately if that is your goal.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

