Skip to content

Instantly share code, notes, and snippets.

@icetan
Last active April 27, 2022 07:39
Show Gist options
  • Save icetan/711ed132fbff05d371c93b8d4d11f1cd to your computer and use it in GitHub Desktop.
Save icetan/711ed132fbff05d371c93b8d4d11f1cd to your computer and use it in GitHub Desktop.
A bash to traverse a path upwards to find a certain file or directory
rtrav() { [ -e "$2/$1" ] && echo "$2" || { [ "$2" != / ] && rtrav "$1" "$(dirname "$2")"; }; }
# Find node_modules directory
rtrav node_modules $PWD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment