Skip to content

Instantly share code, notes, and snippets.

@alvinlai
Created September 1, 2013 15:52
Show Gist options
  • Save alvinlai/6405317 to your computer and use it in GitHub Desktop.
Save alvinlai/6405317 to your computer and use it in GitHub Desktop.
quickly go back up to a specific folder in a directory tree
function bd () {
OLDPWD=`pwd`
NEWPWD=`echo $OLDPWD | sed 's|\(.*/'$1'[^/]*/\).*|\1|'`
index=`echo $NEWPWD | awk '{ print index($1,"/'$1'"); }'`
if [ $index -eq 0 ] ; then
echo "No such occurrence."
else
echo $NEWPWD
cd "$NEWPWD"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment