How to delete history of last 10 commands in shell?

前端 未结 19 1850
孤城傲影
孤城傲影 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:29

    I use this script to delete last 10 commands in history:

    pos=$HISTCMD; start=$(( $pos-11 )); end=$(( $pos-1 )); for i in $(eval echo "{${start}..${end}}"); do history -d $start; done
    

    It uses $HISTCMD environment var to get the history index and uses that to delete last 10 entries in history.

提交回复
热议问题