0

What I usually type:

find . -name "*pattern*"

what I want to type (for example. mnemonic = "all"):

afind . -name "pattern"

or

find . -aname "pattern"

I was just thinking there could be a shortcut like in the style of find . -iname "blah" or rgrep instead of grep -r

Even though, like the grep example, it only saves a couple of characters, they are shifted characters not as easy to type, and it is a commonly used search, probably.

Starman
  • 336
  • 2
  • 11
  • All 3 answers were very much appreciated! I chose the (currently) top voted one because it was short and sweet and directly solved my issue with the least amount of hassle. The one in 2nd place was long, but also technically interesting and very informative. It was hard not to pick that one as well. – Starman May 25 '17 at 21:16

3 Answers3

4

You'd have to roll your own. e.g.:

$ afind () { find "$1" -name "*$2*"; }

$ afind . partial  
./dir/apartialmatch

You can add the definition to your .profile or whatever so that it's always available.

that other guy
  • 116,971
  • 11
  • 170
  • 194
L. Scott Johnson
  • 4,213
  • 2
  • 17
  • 28
2

What you're looking for is a sort of wrapper function for find.

This script should do what you're looking for, and maintain all the other functionality of find.

declare -A params
wild_next=false
for i in $(seq 1 $#); do
    if [[ ${!i} == "-aname" ]]; then
        params[$i]='-name'
        wild_next=true
    else
        if $wild_next; then
            params[$i]="'*${!i}*'"
        else
            params[$i]=${!i}
        fi
        wild_next=false
    fi
done

eval "find ${params[@]}"

It just replaces any instance of the -aname option with -name and puts asterisks around its argument.

Camden Cheek
  • 65
  • 2
  • 7
1

If this is something that you do a lot of, locate would be faster. It's based on the Berkeley Fast Find and is included in the GNU "findutils" package. Note that it gets its data from a database, so its only as current as the last run of updatedb, which is also in the "findutils" package.

Erik Bennett
  • 1,049
  • 6
  • 15