When an unwanted command sits at history number 262, deleting an earlier entry can move it to a new number. I’m fascinated by that shift: Bash numbers positions in a live list, not permanent command identities.
Have Bash display the numbered entries in its active list. See how the session list relates to the file Bash saves.
Bash history has a session list and a file
An interactive Bash shell keeps a numbered history list, and the history builtin displays the current entries.
Bash normally saves entries to ~/.bash_history unless HISTFILE names another file. That file is separate from the active list.
The number beside a command is its current position. Remove an earlier entry and Bash shifts later numbers, which means you should use the current list before each deletion.
history

The list and file are separate. The GNU Bash reference for history builtins documents one option for changing the list and another for writing it to the file.
If repeated commands are hard to tell apart, terminal history with timestamps can help you select the right entry.
Find the numbered entry
Search for a distinctive command fragment, then read the full line before choosing its number. A match can be the search command itself because Bash adds that command to the list too.

The search output includes earlier commands that contain the same text. Use the number beside the exact entry you want, not a nearby match.
If your goal is to clear the entire list rather than remove one entry, use the separate instructions for clearing Bash history.
Delete one entry and write the list
Use the number printed beside the target command. Bash removes that position from the active list, then history -w writes the revised list to HISTFILE.
help history

Step 1. Delete the selected entry
Replace 262 with the number beside your command in the current history output. Bash uses a positive offset as it appears in that numbered list.
history -d 262

Step 2. Save the revised list
Deleting an entry changes the active list. Run history -w to write that list over the file named by HISTFILE.
history -w
I removed sample entry 262 in a disposable Bash 5.2.21 session. The next entry moved into position 262 while the previous entry stayed at 261, and the saved test file omitted sample entry 262.
I used history -w instead of clearing the active list because the task is to keep the other entries. Bash writes the current list over the file, so the selected entry stays out of that file.
Check the list and history file
Check the file path before you inspect the saved history. Bash normally uses ~/.bash_history, but a custom HISTFILE value can send writes to another file.
printf '%s\n' "$HISTFILE"
| Check | What to confirm |
|---|---|
| Current Bash list | Run history and confirm the selected command is absent. |
| Saved history file | HISTFILE names the file that history -w overwrites. |
| Empty destination | When HISTFILE is unset or empty, history -w has no file to write. |
To inspect the saved contents, open the printed path in a text viewer, using the guide to terminal text editors if you need a starting point. Do not paste sensitive command text into another search command because Bash can record the search line too.
The Linux man command guide explains how to read the local manual pages when you need more detail about a shell builtin.
Keep the other history records in scope
history -w overwrites the whole Bash history file with the current list, so check it for entries you still need before writing.
These commands are for Bash only. The article on Linux shell types explains why other shells differ.
Removing an entry does not clear terminal scrollback or erase copies kept elsewhere. A terminal reset changes the display, not Bash history, as explained in the Linux terminal reset guide.
If a command exposed a credential, rotate it at the service before relying on the history edit. A history change cannot recall a value already copied elsewhere.
After the file write, check the active list once more.
history
Bash history deletion questions
Does history -d remove an entry from the history file?
No. It removes the entry from the active Bash history list. Run history -w to write the revised list over the file named by HISTFILE.
Does removing a Bash history entry erase terminal scrollback?
No. Bash history and terminal scrollback are separate. The deletion does not erase other copies in logs, backups, or applications.
