Skip to content

Instantly share code, notes, and snippets.

@fideloper
Created June 16, 2012 15:51
Show Gist options
  • Save fideloper/2941753 to your computer and use it in GitHub Desktop.
Save fideloper/2941753 to your computer and use it in GitHub Desktop.
Shortcut for searching bash history using grep
#! /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
@fideloper
Copy link
Author

Alternatively, (But I don't think strictly needed)

#If bash_history doesn't exist
if [ ! -f /home/${USER}/.bash_history ]; then
    show_usage
else
    cat /home/${USER}/.bash_history | grep $1
fi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment