mastodon.social is one of the many independent Mastodon servers you can use to participate in the fediverse.
The original server operated by the Mastodon gGmbH non-profit

Administered by:

Server stats:

358K
active users

nixCraft 🐧

Want to to delete all `foo` commands from your bash history. Here is how to do it with some bash kung-fu:

line=$(history | grep 'foo' | awk '{ print $1 }' | sort -r)
history -d $line

See cyberciti.biz/faq/delete-comma for more info.

#unix#linux#history

@nixCraft you mean the completely random rm on production?

@mms I understand. You can do echo "$line"and history command to see those commands. This will not remove any files or commands. It will only delete unwanted commands from history file.

@nixCraft As long as all the instances of "sl" are preserved for posterity.

@nixCraft taking out that folder copy command which is ONE char off and starts transfering gigs of content instead of your 27kb file. that is why this is golden.
hitting the up arrow and return key became much too powerful on too little sleep. LOL

PS, it will wake you up really fast to do it my way though! xD

PPS, esp when the target location is a live site... fml. also thanks again.

@nixCraft I'm feeling nerdsniped to find a more concise way to do this

@nixCraft you'll want `sort -rn` (or tac(1) if you have it since they should initially emit in sorted order) to prevent alphabetic ordering. Additionally you can roll the grep into the awk

history | awk '/foo/{print $1}' | sort -rn

@nixCraft `history -a && sed -i '/foo/d' ${HISTFILE}` might work too.