#!/bin/bash # findosaurus # -h for help # if nothing or -t then find files modified in last 3 days if [ "$1" == "-t" ] || [ "$1" == "" ]; then find . -type f -mtime -3 # if --exact elif [ "$1" == "--exact" ] || [ "$1" == "-x" ]; then shift while [ $# -gt 0 ]; do find . -iname "$1" shift done # if --ends elif [ "$1" == "--ends" ] || [ "$1" == "-e" ]; then shift while [ $# -gt 0 ]; do find . -iname \*"$1" shift done # if --starts elif [ "$1" == "--starts" ] || [ "$1" == "-s" ]; then shift while [ $# -gt 0 ]; do find . -iname "$1*" shift done # if --and elif [ "$1" == "--and" ] || [ "$1" == "-a" ]; then shift cons=() # = empty array for arg; do cons+=( -iname "*$arg*" ) done find . "${cons[@]}" # historic note: # according to freenode#bash it would be correct to use arrays and arrays expansion, like: # options=(-name '.*' -type f); find . "${options[@]}" # http://mywiki.wooledge.org/BashFAQ/005 # if --help elif [ "$1" == "-h" ] || [ "$1" == "--help" ]; then echo "findosaurus # last 3 days mtime" echo "arg1 arg2 # search for *arg1* OR *arg2*" echo "-x or --exact arg # search for exact arg" echo "-e or --ends arg # search for ends-with arg" echo "-s or --starts arg # search for starts-with arg" echo "-a or --and arg1 arg2 # search for *arg1* AND *arg2*" echo "-h or --help # this help" echo "findosaurus is meant for interactive use only, always assuming 'this dir ./' is the dir we want to start with." # else search from here using each argument as "pattern", this is OR else cons=() for arg; do cons+=( -o -iname "*$arg*" ) done unset -v 'cons[0]' # remove first -o find . "${cons[@]}" # ^ geirha fi