How to delete a specific command history and when you enter that "command" that will delete the specific command?

For example, here is my history:

1 ls -l
2 cat > foo.txt
3 ifconfig
4 echo "Hello"

Now, I want to delete the ifconfig command history which is Number: 3, so I'll do the following command: history -d 3 ( which will delete the ifconfig command).

The second one is, I want to delete that command I recently typed (history -d 3) or in other words, this command will not be remembered in history, so no one can see that I just deleted a specific command history.

To summarize, the ifconfig command history will be deleted and the recently type history -d 3 command will not be remembered/logged in history.



1 Answer 1


Not exactly what you are looking for but maybe still a possible/usefull workaround.

You can setup your history to ignore Commands which have a space as first character. You can add this functionallity by adding the following line to your .bashrc


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.