bash

Reverse Find

I recently had need to do a reverse find, and couldn’t discover any programs that offer this functionality. I decided to work around the issue using a bash function, loops, and find. This function can be stuffed into your ~/.bash_profile, and referenced wherever you need it. rfind() { rfind_path="${PWD}" while [[ "${rfind_path}" != "/" ]]; do rfind_search_paths="${rfind_search_paths} ${rfind_path}" rfind_path=$(dirname "${rfind_path}") done find ${rfind_search_paths} / -maxdepth 1 $@ -print -quit } As an example, let’s say I’m in /home/user/docs, and I execute rfind somefile.