Skip to main content

Clearing Command Line History

There's a few options here, also see the history man page for more info.

1. Remove the command from bash history using the history -d command:

history -d LINE-NUMBER

The downside of this, is that the command run to delete the history will be included in the bash history, this brings us on to the sneakier method.

2. When running the history -d command, preface the command with a space. A leading space before a command instructs the shell to ignore it for history logging.

 history -d LINE-NUMBER

3. Finally, there's another option we can use to clear the entire bash history:

history -c