# Lazy find by Klaatu Here's the scenario: I download some source code or a bundle of art assets or a game from the Internet, it gets downloaded to my **~/Downloads** directory, and then I navigate to the Downloads folder and promptly forget the file name. It's not that I don't remember what I downloaded, it's the proliferation of file types that throws me off. Was it a [tarball](https://opensource.com/article/17/7/how-unzip-targz-file) or a ZIP file? What was the version number? Had I already downloaded a copy before? In short, there are too many variables for me to confidently issue a command without listing the contents of **~/Downloads** and grepping for some substring of the filename. To make this process easy for myself, I keep a command I call **lf** in my **~/bin** directory. It's a simple front-end to the popular **find** or **locate** command, but with less typing and far less functionality. To find a file located in the current directory, containing the string *foo* in its filename: ``` $ lf foo ``` To find a file located in some other directory, containing the string *foo* in its filename: ``` $ lf --path ~/path/to/dir foo ``` It's purely a lazy tool, and as I am very lazy, it's one I use frequently. ``` #!/bin/sh # lazy find # GNU All-Permissive License # Copying and distribution of this file, with or without modification, # are permitted in any medium without royalty provided the copyright # notice and this notice are preserved. This file is offered as-is, # without any warranty. ## help function function helpu { echo " " echo "Fuzzy search for filename." echo "$0 [--match-case|--path] filename" echo " " exit } ## set variables MATCH="-iname" PATH="." ## parse options while [ True ]; do if [ "$1" = "--help" -o "$1" = "-h" ]; then helpu elif [ "$1" = "--match-case" -o "$1" = "-m" ]; then MATCH="-name" shift 1 elif [ "$1" = "--path" -o "$1" = "-p" ]; then PATH="${2}" shift 2 else break fi done ## sanitize input filenames ## create array, retain spaces ARG=( "${@}" ) set -e ## catch obvious input error if [ "X$ARG" = "X" ]; then helpu fi ## perform search for query in ${ARG[*]}; do /usr/bin/find "${PATH}" "${MATCH}" "*${ARG}*" done ```