How to Delete History Without a trace in Linux?

Linux “bash history” maintains the list of all the previously executed commands by the logged-in user. These commands can be accessed by pressing the “up arrow” key from the keyboard. This process can invoke a security issue as the command’s history of one user can be traced using arrow keys.

To avoid this, it is recommended to delete the history without a trace. In doing so, the previous commands cannot be retrieved using arrow keys. 

This guide illustrates all the possible aspects of deleting history without a trace in Linux. 

Method 1: Use the “history” Command to Delete History

The “history” command line tool is utilized to list down the recently executed commands in the terminal organized by the unique event number. By default, it displays the last five hundred commands the user entered in the terminal shell.

Example 1: Delete the History Completely

The “-c (clear)” flag of the “history” deletes or clears the complete history of the Linux system. In this example, the current working system “Ubuntu” history is deleted using the following command:

$ history -c

The above command executed successfully without an error and deleted all the history. 

Example 2: Delete Specific Command From the History

Instead of deleting the complete history, the user can also delete/remove the “Nth” specified command. For this purpose, use the -d” flag to delete the specified command from the history.

Suppose the “history” command contains the “sudo apt update” command having an event id “5”:

$ history

Execute the “history” command followed by the “-d” flag and the event id of the desired command in this way:

$ history -d 5

The “sudo apt update” has been deleted from the history as shown in the output.

Method 2: Use the “wipe” Tool to Delete History

Here is another command line tool to delete history without leaving a trace is “wipe” command. The “wipe” command is beneficial for erasing all the data from the disk permanently and securely. However, the removed data can not be recovered after executing this command.

Install “wipe” Command

The “wipe” command is an external command and is not installed in most of the Linux distributions, so first install it using the following commands:

$ sudo yum install wipe                               # For CentOS/RHEL
$ sudo dnf install wipe                               # For Fedora
$ sudo apt install wipe                               # For Debian/Ubuntu-Based

Delete the History

When the “wipe” is installed successfully then execute it by specifying the “~/.bashrc_file” to delete the history of “Ubuntu 22.04” without a trace:

$ wipe ~/.bashrc_history

The output confirms that the “.bashrc_history” file has been completely wiped.

Conclusion

In Linux, use the “history” and “wipe” command line tools to delete the system history without a trace. The “history” command is pre-installed, while the “wipe” command is installed through the “apt” package manager. Both these commands completely cleared or wiped out the system history. This post has illustrated all the possible methods to delete history without a trace.