Read more

How to remove entries from the bash history

Judith Roth
December 02, 2020Software engineer at makandra GmbH

Sometimes you accidentally generate entries in the bash history that you do not want to have there (e.g. commands with credentials).
Here's how to remove single entries.

Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

You can look at the bash history with the history command.
To see e.g. the last 5 entries, use history | tail -n 5:

>history | tail -n 5
 1994  my-secret-command
 1995  cd xyz-mnt/
 1996  ls
 1997  cd appliance/
 1998  cd ..

Each entry has a number. You can use that to delete it: history -d 1994. Note that as you delete entries, the numbers of the following entries will change.

Posted by Judith Roth to makandra dev (2020-12-02 10:43)