1

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.

Thanks!

  • If HISTCONTROL is set to ignore lines that begin with a space, then add a space in front of the history -d ... command. – dsstorefile1 Sep 21 '18 at 9:14
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

HISTCONTROL=ignorespace

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.