Skip to content

Instantly share code, notes, and snippets.

@verityj
Last active June 21, 2023 11:21
Show Gist options
  • Save verityj/e7d4a634c0e258fcf162097c826e2668 to your computer and use it in GitHub Desktop.
Save verityj/e7d4a634c0e258fcf162097c826e2668 to your computer and use it in GitHub Desktop.
Shell script: search in specified location for files containing a string inside (not case sensitive)
#!/bin/zsh
# Written by: VerityJ
# Published on: https://gist.github.com/verityj
#
# Usage: ./find-inside.sh location search-string
# location should not end in /*
# search-string does not need " or *
#
# Output: file names that contain the search-string inside
if [ -z "$2" ]
then
echo "Usage: ./find-inside.sh <location> <search-string> (note: no need for \" or *)"
echo "<location> example: ~ (user home) or . (current directory)"
exit 0
fi
printf "\nSearching in '$1/*' for \"$2\" (case-insensitive) ...\n\n"
grep -lir "$2" "$1"/*
# -l outputs file name list
# -i ignore case
# -r recursive search
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment