Skip to content

Instantly share code, notes, and snippets.

@lionelyoung
Created July 9, 2017 02:49
Show Gist options
  • Save lionelyoung/e889d20deb318e71b3fe775d059e2aa6 to your computer and use it in GitHub Desktop.
Save lionelyoung/e889d20deb318e71b3fe775d059e2aa6 to your computer and use it in GitHub Desktop.
Find a subdirectory name with maxdepth
# Find dir
# https://stackoverflow.com/questions/2824504/how-do-i-prevent-find-from-printing-git-folders
function finddir () {
# Defaults
DEPTH=4
# Arg check
if [ "$#" -gt 2 ] || [ "$#" -lt 1 ] ; then
echo "Illegal number of parameters"
fi
# override defaults if not empty
if ! [ -z "$2" ]; then
echo "Overriding DEPTH with $2"
DEPTH=$2
fi
###########################
# Execute the find command
###########################
echo "Searching for '$1' with -maxdepth $DEPTH"
find . -name '.git*' -prune -o -name "*$1*" -maxdepth $DEPTH -type d -print
}
alias fd="finddir"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment