Skip to content

Instantly share code, notes, and snippets.

@emilyst
Created September 14, 2012 21:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emilyst/3724875 to your computer and use it in GitHub Desktop.
Save emilyst/3724875 to your computer and use it in GitHub Desktop.
# Find a file
function ff() { find . -type f -iname '*'$*'*' -ls ; }
# Find a file with pattern $1 in name and execute $2 on it
function fe() { find . -type f -iname '*'${1:-}'*' -exec ${2:-file} {} \; ; }
# Find a pattern in a set of files and highlight them
# (needs a recent version of egrep)
function fs()
{
OPTIND=1
local case=""
local usage="fs: find string in files.
Usage: fs [-i] \"pattern\" [\"filename pattern\"] "
while getopts :it opt
do
case "$opt" in
i) case="-i " ;;
*) echo "$usage"; return;;
esac
done
shift $(( $OPTIND - 1 ))
if [ "$#" -lt 1 ]; then
echo "$usage"
return;
fi
find . -type f -name "${2:-*}" -print0 | \
xargs -0 zegrep --color=always -sn ${case} "$1" 2>&- | more
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment