I'm nested deep in a file tree, and I'd like to find which parent directory contains a file.E.g. I'm in a set of nested Git repositories and want to find the .git directory controlling the files I'm currently at. I'd hope for something like find -searchup -iname .git
find searching in parent directories instead of subdirectories
shell;find
An even more general version that allows using find options:#!/bin/bashset -epath=$1shift 1while [[ $path != / ]];do    find $path -maxdepth 1 -mindepth 1 $@    # Note: if you want to ignore symlinks, use $(realpath -s $path/..)    path=$(readlink -f $path/..)doneFor example (assuming the script is saved as find_up.sh)find_up.sh some_dir -iname foo*bar -execdir pwd \;...will print the names of all of some_dir's ancestors (including itself) up to / in which a file with the pattern is found.When using readlink -f the above script will follow symlinks on the way up, as noted in the comments. You can use realpath -s instead, if you want to follow paths up by name (/foo/bar will go up to foo even if bar is a symlink) - however that requires installing realpath which isn't installed by default on most platforms.