Interactive Bash shows that the unwanted history entry has number 42.
Delete only that entry from the history list.
Which command is appropriate?
history -d OFFSET deletes the entry at the specified history position. This is different from -c, which clears the entire list.
Detailed explanation
history 42Incorrect. It displays entry 42 but does not delete it.
Incorrect. It displays entry 42 but does not delete it.
history -d 42Correct. -d 42 deletes the history item at that position.
Correct. -d 42 deletes the history item at that position.
history -c 42Incorrect. -c clears all history entries.
Incorrect. -c clears all history entries.
history -a 42Incorrect. -a appends recent entries to the history file.
Incorrect. -a appends recent entries to the history file.
Try it yourself
An example you can run in a temporary verification environment.
対話的Bashでhistory -d 42を実行後、historyで確認するExpected result
元の履歴番号42の項目が一覧からなくなるKey points
- history -d
- history -c versus one-entry deletion
- History offsets
Notes
- Environment: Bash 5.2(対話モード)
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.