Skip to content

Instantly share code, notes, and snippets.

@flacodirt
Created April 19, 2013 00:16
Show Gist options
  • Save flacodirt/5417203 to your computer and use it in GitHub Desktop.
Save flacodirt/5417203 to your computer and use it in GitHub Desktop.
Clear bash history of any lines matching keyword
#!/bin/bash
#
echo '# @author brockhensley'
echo '# @version 1.0.0'
echo '# @date Last updated April 18th 2013'
echo '# @link brockhensley.com'
if [ -z "$@" ]
then
echo '#'
echo '# Enter search string to clear from history as parameter'
echo '#'
echo '# Example: ./clearhistory.sh anythingwiththisword'
echo '#'
exit 0
fi
for var in "$@"
do
grep -v $var "$HISTFILE" > /tmp/history
mv /tmp/history "$HISTFILE"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment