How to clear all history in linux/ubuntu terminal or bash permanently?

LinuxBashUbuntuTerminal

Linux Problem Overview


When you use the up key in a Linux terminal, you can use previous commands again. Great feature. However, I started logging mysql into mysql with the sensitive details in the command.

How can I delete that history permanently?

Linux Solutions


Solution 1 - Linux

You can clear your bash history like this:

history -cw

Solution 2 - Linux

If you use bash, then the terminal history is saved in a file called .bash_history. Delete it, and history will be gone.

However, for MySQL the better approach is not to enter the password in the command line. If you just specify the -p option, without a value, then you will be prompted for the password and it won't be logged.

Another option, if you don't want to enter your password every time, is to store it in a my.cnf file. Create a file named ~/.my.cnf with something like:

[client]
user = <username>
password = <password>

Make sure to change the file permissions so that only you can read the file.

Of course, this way your password is still saved in a plaintext file in your home directory, just like it was previously saved in .bash_history.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionFrank VileaView Question on Stackoverflow
Solution 1 - LinuxEddieView Answer on Stackoverflow
Solution 2 - LinuxsagiView Answer on Stackoverflow