How to delete history of last 10 commands in shell?

前端 未结 19 2018
孤城傲影
孤城傲影 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条回答
  •  萌比男神i
    2021-01-29 19:30

    First, type: history and write down the sequence of line numbers you want to remove.

    To clear lines from let's say line 1800 to 1815 write the following in terminal:

    $ for line in $(seq 1800 1815) ; do history -d 1800; done
    

    If you want to delete the history for the deletion command, add +1 for 1815 = 1816 and history for that sequence + the deletion command will be deleted.

    For example :

    $ for line in $(seq 1800 1816) ; do history -d 1800; done
    

提交回复
热议问题