-
-
Save maxsu/6128886 to your computer and use it in GitHub Desktop.
Find Script
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 | |
# usage: myfind [-d DIR] STRING [...] | |
# finds all files matching any given STRING in DIR, or the current working | |
# directory if DIR is not provided | |
arg=. | |
args=. | |
dir=. | |
# if -d was used, store DIR and shift away -d DIR | |
if [[ $1 = -d ]]; then | |
dir=$2 | |
shift 2 | |
fi | |
# make sure at least one STRING was provided | |
if ((!$#)); then | |
cat <<'EOF' >&2 | |
usage: myfind [-d DIR] STRING [...] | |
finds all files matching any given STRING in DIR, or the current working | |
directory if DIR is not provided | |
EOF | |
return 1 | |
fi | |
# create list of arguments for find | |
args=(-iname "*$1*") | |
shift | |
for arg; do | |
args+=(-o -iname "*$arg*") | |
done | |
# run the actual find command | |
find "$dir" \( "${args[@]}" \) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment