How To Clear Shell History In Ubuntu Linux

To clear the shell history in Ubuntu Linux, you can follow these steps:

  1. Open a terminal window.
  2. To clear the entire shell history, use the following command:
history -c

This will clear all the commands from the history file.

  1. If you want to clear a specific command from the history, you can use the history command to display the history, find the line number of the command you want to remove, and then use the history -d command to delete it. For example, to delete the command on line 10, you can use the following command:
history
history -d 10
  1. To prevent the shell from recording commands in the history file, you can add the following line to your .bashrc or .bash_profile file:
export HISTSIZE=0

This will set the history size to zero, so commands will not be saved to the history file.

Note that clearing the shell history can be useful if you want to keep your command history private, but it can also be a security risk if you are using a shared account or if someone gains access to your account. It is also worth noting that clearing the shell history does not delete any files or logs created by the commands you ran. To remove files or logs created by a command, you will need to do so manually.

Leave a Comment