Reputation: 12320
I have tried the below
history -d $(history | grep "echo.*" |awk '{print $1}')
But it is not deleting all the commands from the history with echo
I want to delete any commands start with echo
like
echo "mamam"
echoaaa
echo "hello"
echooooo
Upvotes: 0
Views: 233
Reputation: 901
history -w
sed -i '/^echo.*/d' ~/.bash_history
history -c
history -r
Upvotes: 0
Reputation: 26437
You can use this to remove echo
entries :
for d in $(history | grep -Po '^\s*\K(\d+)(?= +echo)' | sort -nr); do history -d $d; done
Upvotes: 1
Reputation: 22225
I would do a
history -d $(history | grep -E "^ *[0-9]+ *echo" | awk '{print $1})
The history command produces one column of event number, followed by the command. We need to match an echo, which is following such a event number. The awk then prints just the event number.
An alternative without reverting to awk would be:
history -d $(history | grep -E "^ *[0-9]+ *echo" | grep -Eow '[0-9]+)
Upvotes: 1