-
-
Save fideloper/2941753 to your computer and use it in GitHub Desktop.
Shortcut for searching bash history using grep
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
function show_usage { | |
cat <<- _EOF_ | |
Search Bash History using Grep | |
Examples: | |
$ h ssh | |
$ h 'ssh user@' | |
_EOF_ | |
exit 1 | |
} | |
#Sanity check - Need one argument | |
if [ $# -ne 1 ]; then | |
show_usage | |
fi | |
#If bash_history doesn't exist | |
if [ ! -f ~/.bash_history ]; then | |
show_usage | |
else | |
cat ~/.bash_history | grep $1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Alternatively, (But I don't think strictly needed)