Use incomplete file path in terminal

command linepathterminal

In terminal is there a way for Terminal to guess a file based on an incomplete file path? For example:
Instead of /Users/me/foo1/foo2/foo3/foo4/TargetFile, is there a way to just do /foo3/foo4/TargetFile?
I want to be able to access the file no matter where it is. Thanks.

Best Answer

If the file's path is relative to the current working directory your could use:

find . -name targetfile

You could wrap this in a shell function:

mylocate () {
    find . -name "$1"
}

# Usage
mylocate targetfile

In zsh you can use the globstar feature:

printf '%s\n' **/targetfile

In ksh:

set -G
printf '%s\n' **/targetfile

In bash4:

shopt -s globstar
printf '%s\n' **/targetfile