find-type.sh 467 B

12345678910111213141516
  1. #!/usr/bin/env bash
  2. set -euo pipefail # bash strict mode
  3. mimetypes=$(sed -E 's/\/.*//g; /^$/d; /^#/d' /etc/mime.types | uniq)
  4. display_help(){
  5. echo "Usage: ${0##*/} [mimetype]"
  6. echo "Available mimetypes:"
  7. echo "$mimetypes"
  8. exit 2
  9. }
  10. [[ $# -lt 1 ]] && display_help
  11. ext=$(sed -E "/^${1}/!d; s/^[^ \t]+[ \t]*//g; /^$/d; s/ /\n/g" /etc/mime.types | sed -Ez 's/\n$//; s/\n/\\|/g; s/(.*)/\.*\\.\\(\1\\)\n/')
  12. find -type f -regex "$ext" "${@:2}" 2>/dev/null