Skip to content

Instantly share code, notes, and snippets.

@rmackinnon
Created July 21, 2017 19:32
Show Gist options
  • Save rmackinnon/2432ccb8f2c613eb3fe13268bdd01c15 to your computer and use it in GitHub Desktop.
Save rmackinnon/2432ccb8f2c613eb3fe13268bdd01c15 to your computer and use it in GitHub Desktop.
Reverse Find: Recurse upward from CWD to root and list any files matching.
#!/bin/bash
# Reverse Find: Recurse upward from CWD to root and list any files matching.
if [ $# -eq 0 ]; then
echo "Usage: revfind [-d dir] <filename>"
exit 1
fi
if [ $1 == '-d' ]; then
shift
START_WD=`pwd`
cd $1
shift
fi;
FILENAME="$1"
while [ true ];
do
pwd=`pwd`
[ -e $FILENAME ] && echo $pwd`[ ! "$pwd" == '/' ] && echo '/'`$FILENAME
[ "$pwd" == '/' ] && break
cd ..
done
[ -n $START_WD ] && cd "${START_WD}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment