Find Text Inside Multiple Files Recursively Using Bash
- Category Shell
- Type Command
- Platform Linux
- Language Bash
- Price Free
- Copy 1 660
- Comments 0
Find Text Inside Multiple Files Recursively Using Bash
#!/usr/bin/env bash
# Search for a specific string inside all files in the target directory
# Usage: ./search-text.sh "search_term" [path]
SEARCH_TERM="$1"
SEARCH_PATH="${2:-.}"
if [ -z "$SEARCH_TERM" ]; then
echo "Error: Please provide a search term."
echo "Usage: $0 "search_term" [path]"
exit 1
fi
grep -rnw "$SEARCH_PATH" -e "$SEARCH_TERM" --color=always
Free snippet — copy & paste!
Copy this snippet for free on Clayi Code. One click — no account required.
There are no comments yet :(