How to delete entries from fish shell's command history?

6.1k Views Asked by At

In an attempt to unlock the screen, I have accidentally entered my password into a terminal running the fish shell.

How can I remove it from the command history of fish again?

The solution does not need to be forensically secure. Traces left in backup files or on the drive are fine with me. I just want to avoid e.g. my password accidentally popping up in a screen sharing session when I use fish's history while sharing. And I want to keep all the other commands in the history, because I often recall complicated commands from the history, sometimes editing them before reusing.

3

There are 3 best solutions below

0
On BEST ANSWER

You want history delete. That should ask you for a search term, show you matching entries and ask you for which to delete.

0
On

I found the default folder on linux is ~/.local/share/fish/fish_history. This is very similar to .bash_history. You must be able to view and manipulate history in a non-programmatic and flexible way.

0
On

Just an addition to history delete.

--contains / -c - Shows you the results in a prompt before it gets deleted. Since it is the default, you do not need to specify the flag as shown in the examples.

  • history delete --contains "supersecretpw"
  • history delete -c "supersecretpw"
  • history delete "supersecretpw"

Another handy shortcut history clear-session will only delete the current session.