The shell Bash saves the commands entered in a history file defined in the HISTFILE variable; you can use it to retrieve the list of previously entered commands with the command history. By default, the history normally shows a numbered list of the last 500 commands entered; the value of the HISTSIZE variable is used to define the number of commands to save in the history list.
In this article, we will explain how to delete the entire history or partially clear it, and even disable it.
How to clear the user's entire history
To clear the history, simply use the option to repaint by clearing rather than scrolling and the option to highlight the first new line after advancing the screen:
# history -cwOnce it has run, you will start the user's history over again.
How to clear the user's history and exit without leaving a trace
Simply run the previous command, but add Exit with the logical AND operator:
# history -cw && exitYou will exit without leaving even Exit in the user's Bash history.
How to clear the history manually
You can also edit the history to change or delete a line, for example; you can check the history file variable to find it:
# echo "$HISTFILE"The history path for the user will appear; you can edit it with an editor:
# nano /root/.bash_historyHowever, the history in memory will not appear; to edit what was entered during the session, you must first save it:
# history -w && nano /root/.bash_historyHow to disable Bash history
Finally, if you do not want to store history, you can simply unset the variable for the file:
# unset HISTFILEYou will only have the history in memory; when you exit the session, it will not be stored.
We hope this article has helped you. If you still have questions about this or any other issue related to your servers on Clouding, write to us at soporte@clouding.io. We're here to help! 😉