3 ms·
Shorthand to find all files matching a pattern (with optional additional arguments, e.g., -delete, -ls, -exec ..., etc. fndi () { tgt="${1}";
by PeterWhittaker 4y ago
Shorthand to find all files matching a pattern (with optional additional arguments, e.g., -delete, -ls, -exec ..., etc.
fndi ()
{
tgt="${1}";
shift;
echo find . -iname \*"${tgt}"\* "${@}";
find . -iname \*"${tgt}"\* "${@}" 2> /dev/null;
[[ -z $tgt ]] && {
echo;
echo "No target was specified, did the results surprise?"
}
}
Shorthand to find all files containing a pattern:
fndg ()
{
binOpt="-I";
wordOpt="";
caseOpt="-i";
while true; do
if [[ -z $1 || $1 =~ ^[^-+] ]]; then
break;
fi;
case $1 in
+i)
caseOpt=""
;;
-B)
binOpt=""
;;
-w)
wordOpt="-w"
;;
*)
echo "Unrecognized option '${1}', cannot proceed.";
return 1
;;
esac;
shift;
done;
if [[ -z $2 ]]; then
startIn=.;
else
startIn='';
while [[ ! -z $2 ]]; do
startIn+="$1 ";
shift;
done;
fi;
[[ -z $1 ]] && {
echo "No target specified, cannot proceed.";
return
};
tgt=$1;
echo find ${startIn} -type f -exec grep $binOpt $wordOpt $caseOpt -H "${tgt}" {} \;;
find ${startIn} -type f -exec grep $binOpt $wordOpt $caseOpt -H "${tgt}" {} \; 2> /dev/null
}