How to delete history of last 10 commands in shell?

前端 未结 19 2022
孤城傲影
孤城傲影 2021-01-29 18:47

Commands follows

  511  clear
  512  history
  513  history -d 505
  514  history
  515  history -d 507 510 513
  516  history
  517  history -d 509
  518  hist         


        
19条回答
  •  我在风中等你
    2021-01-29 19:28

    edit:

    Changed the braced iterators, good call. Also, call this function with a reverse iterator.

    You can probably do something like this:

    #!/bin/bash
    HISTFILE=~/.bash_history   # if you are running it in a 
                               # non interactive shell history would not work else
    set -o history
    for i in `seq $1 $2`;
    do
        history -d $i
    done
    history -w
    

    Where you will evoke like this:

    ./nameOfYourScript 563 514
    

    Notice I haven't put any error checking in for the bounds. I'll leave that as an exercise to the reader.

    see also this question

提交回复
热议问题