Reputation: 375
How to write a bash command that finds all files in the current directory that contain the word “foo”, regardless of case?
Upvotes: 3
Views: 259
Reputation: 34654
If you want "foo" to be the checked against the contests of the files in .
, do this:
grep . -rsni -e "foo"
for more options (-I, -T, ...) see man grep
.
Upvotes: 2
Reputation: 3094
I've always used this little shell command:
gfind () { if [ $# -lt 2 ]; then files="*"; search="${1}"; else files="${1}"; search="${2}"; fi; find . -name "$files" -a ! -wholename '*/.*' -exec grep -Hin ${3} "$search" {} \; ; }
you call it by either gfind '*php' 'search string'
or if you want to search all files gfind 'search string'
Upvotes: 0
Reputation: 30309
Assuming you want to search inside the files (not the filenames)
If you only want the current directory to be searched (not the tree)
grep * -nsie "foo"
if you want to scan the entire tree (from the current directory)
grep . -nsrie "foo"
Upvotes: 1
Reputation: 166322
Try:
echo *foo*
will print file/dir names matching *foo*
in the current directory, which happens to match any name containing 'foo'.
Upvotes: 0
Reputation: 342949
shopt -s nullglob
shopt -s nocaseglob
for file in *foo*
...
...
..
Upvotes: 0