Unix bash command

How to write a bash command that finds all the files in the current directory that contain the word "foo", regardless of the case?

+3
source share
6 answers

Assuming you want to search inside files (not file names)

If you only need to search the current directory (and not the tree)

grep * -nsie "foo"

if you want to scan the whole tree (from the current directory)

grep . -nsrie "foo"
+1
source

If you want "foo" to be marked against file contests in ., do the following:

grep . -rsni -e "foo"

for additional parameters (-I, -T, ...) see man grep.

+2
source
shopt -s nullglob
shopt -s nocaseglob
for file in *foo*
...
...
..
0

Try:

echo *foo*

/dir, *foo* , , "foo".

0

:

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 either with gfind '*php' 'search string'or if you want to search all filesgfind 'search string'

0
source

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

-1
source

Source: https://habr.com/ru/post/1762380/


All Articles