Quantcast
Channel: How to delete history of last 10 commands in shell? - Stack Overflow
Viewing all articles
Browse latest Browse all 23

Answer by ata for How to delete history of last 10 commands in shell?

$
0
0

I use this (I have bash 4):

histrm() {    local num=${1:- 1}    builtin history -d $(builtin history | sed -rn '$s/^[^[:digit:]]+([[:digit:]]+)[^[:digit:]].*$/\1/p')    (( num-- )) && $FUNCNAME $num    builtin history -w}

The builtin history parts as well as the last -w is because I have in place a variation of the famous tricks to share history across terminals and this function would break without those parts. They ensure a call to the real bash history builtin (and not to my own wrapper around it), and to write the history to HISTFILE right after the entries were removed.

However this will work as it is with "normal" history configurations.

You should call it with the number of last entries you want to remove, for example:

histrm 10

Will remove the last 10 entries.


Viewing all articles
Browse latest Browse all 23

Trending Articles