How to delete history of last 10 commands in shell?

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

    history -c will clear all histories.

    0 讨论(0)
  • 2021-01-29 19:35

    Have you tried editing the history file directly:

    ~/.bash_history
    
    0 讨论(0)
  • 2021-01-29 19:35

    I used a combination of solutions shared in this thread to erase the trace in commands history. First, I verified where is saved commands history with:

    echo $HISTFILE
    

    I edited the history with:

    vi <pathToFile>
    

    After that, I flush current session history buffer with:

    history -r && exit
    

    Next time you enter to this session, the last command that you will see on command history is the last that you left on pathToFile.

    0 讨论(0)
  • 2021-01-29 19:35

    Not directly the requested answer, but maybe the root-cause of the question:

    You can also prevent commands from even getting into the history, by prefixing them with a space character:

    # This command will be in the history
    echo Hello world
    
    # This will not
     echo Hello world
    
    0 讨论(0)
  • 2021-01-29 19:38

    to delete last 10 entries (based on your example) :

    history -d 511 520
    
    0 讨论(0)
  • 2021-01-29 19:39
    for x in `seq $1 $2`
    do
      history -d $1
    done
    
    0 讨论(0)
提交回复
热议问题