Created
July 21, 2017 19:32
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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