Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • 3
    Be sure to use the higher number for the first argument or you will delete every other command. E.g. when command 511 is deleted, everything shifts down so 512 becomes the new 511 and 513 is the new 512. Therefor history -d 511 works as expected, then history -d 512 deletes what used to be 513, and 512 remains in the history as command 511. Hope that makes sense.
    – Matthew
    Commented Dec 8, 2015 at 21:12
  • 6
    @Matthew That's not necessary. I'm not deleting $x each time through the loop, I'm deleting $1. So it first deletes 511,and 512 becomes 511. Then it deletes 511 again, and so on.
    – Barmar
    Commented Dec 8, 2015 at 21:37
  • @Matthew Notice that I made a similar comment to Tyler's answer. I came up with my solution as a fix for that.
    – Barmar
    Commented Dec 8, 2015 at 21:38
  • 1
    you are correct, in my haste when wrote this out in a single line in my bash prompt I used for i in ... and history -d $i and got the results I described in my comment above. Using $1 this absolutely is correct as stated in your original answer.
    – Matthew
    Commented Dec 8, 2015 at 23:46