Let's say I ran a command using a zsh
echo "mysecret" > file
I can easily print the history including the entry numbers using the command fc -l
:
1 echo "mysecret" >| file
But how can I easily delete an entry from the history?
I cannot find a corresponding paragraph in man zshbuiltins.
In my terminal, ZSH, there's a file called ~/. zsh_history , and a similar one for Bash. To remove the command, open that file and remove the entry from the list. Open a new terminal window, and the bad command is gone.
ZSH is a popular shell built on top of bash. It stores your command history in the . zsh_history file in your home directory.
Clear all bash history by using history command: 'ls' command will display the list of the files and folders of the current location. 'clear' command will clear the terminal screen.
LC_ALL=C sed -i '' '/porn/d' $HISTFILE
LC_ALL=C sed -i '/porn/d' $HISTFILE
This will remove all lines matching "porn" from your $HISTFILE.
With setopt HIST_IGNORE_SPACE
, you can prepend the above command with a space character to prevent it from being written to $HISTFILE.
As Tim pointed out in his comment below, the prefix LC_ALL=C prevents 'illegal byte sequence' failure.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With