Notion app logo
Struggling to stay organized and effective? Learn to master your time and tasks with the Effectively Notion course!

Delete Command from Bash History


I spend a lot of time in the Terminal typing bash commands, but it never fails that I want to re-run a command or most of a command and can't remember what it is (anyone else forget how to spell the word am...end when typing git commit --amend -m "change my commit message"?! (yeah, I always add an extra "m" the first time))

If you use the reverse search functionality, you've probably used your history to do this. The only way to determine if that command was maybe the right command is by running it and seeing it fail or succeed.

The best way to keep your bash history from potentially giving you bad info is to delete the command from your history after you've done it wrong. As an example, here are the last 4 items from my bash history:

$ history 4
 4449  ls
 4450  mkdire foo
 4451  mkdir foo
 4452  history 4

history gives you the entry number and the command that was run. Passing history a 4 means I only want the last 4 commands that were executed (it'll include itself in this list because it was executed).

I want to remove mkdire foo because mkdire should be mkdir and I don't want to ever accidentally re-run it with reverse search. You can pass -d and the entry number to delete the entry:

$ history -d 4450

Now if I run history 4 again, I get the following results:

$ history 4
 4450  mkdir foo
 4451  history 3
 4452  history -d 4450
 4453  history 4

Now when I do a reverse search, I won't find that result again! 🎉

Photo of Chase Adams

Hey, I'm Chase. I help aspiring entrepreneurs and makers turn their ideas into digital products and apps.


Vector Arrow Scribbles
banner image for figma vector arrows scribbles

A figma community project of vectorized hand-drawn arrows.

Go To Figma
Vector Line Scribbles
banner for figma vector line scribbles

A figma community project of vectorized hand-drawn lines.

Go To Figma
Vector Shape Scribbles
banner image of figma vector shapes scribbles

A figma community project of vectorized hand-drawn shapes.

Go To Figma

Subscribe to my Newsletter

Every other week I publish the Curiously Crafted newsletter.

In it, I explore the intersection of curiosity and craft: the people who make stuff, what they make and the way they pursue the craft of making.


I'm on almost all social media as @curiouslychase.

The curious logo of Chase Adams: glasses and a bow tie.stay curious.