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 https://www.cyberciti.biz/faq/delete-command-from-history-linux-unix-osx-bash-shell/ for more info.
@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.
Boosted AND bookmarked!
@nixCraft As long as all the instances of "sl" are preserved for posterity.
@jesse haha. yes.
@nixCraft Why?
Evade audits?
@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 awk '/foo/ {print $1}'
@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.