scoohh
scoohh

Reputation: 375

unix bash command

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

Answers (6)

bitmask
bitmask

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

icco
icco

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

ocodo
ocodo

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

hasen
hasen

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

ghostdog74
ghostdog74

Reputation: 342949

shopt -s nullglob
shopt -s nocaseglob
for file in *foo*
...
...
..

Upvotes: 0

dj_segfault
dj_segfault

Reputation: 12449

find . -type f | grep -i "foo"

Upvotes: -1

Related Questions