In this quick post, we’ll see how to clear the last commands stored in the bash history. Imagine the following situation: an analysis on a server that you would not want to leave stored in the bash history the commands used.

Type the history command to see the line numbers that you want to delete. Imagine that you need to delete the lines between 100 and 120 copy and paste the command below, or change the number of lines as needed.

for h in $(seq 100 120 | tac); do history -d$h;
done