How to write a bash command that finds all files in the current directory that contain the word “foo”, regardless of case?
that would find FILENAMES that contain "foo", not contained text. (and recurse the directory tree)
slomojo
2010-08-31 00:50:26
and there's no need to use grep.use find's -iname or -name
ghostdog74
2010-08-31 01:02:21
If you want to wrap it in a script so you can just type "findnocase foo", it should look like this:find . -type f | grep -i $1
dj_segfault
2010-08-31 01:14:51
ghostdog is right. It can be simplified as "find . -maxdepth 1 -type f -iname $1". If slomojo is right and you mean you want to search the contents of the file, then all you need is "grep -i $1 *"
dj_segfault
2010-08-31 01:20:48
A:
shopt -s nullglob
shopt -s nocaseglob
for file in *foo*
...
...
..
ghostdog74
2010-08-31 00:17:50
+2
A:
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
.
bitmask
2010-08-31 00:33:54
A:
Try:
echo *foo*
will print file/dir names matching *foo*
in the current directory, which happens to match any name containing 'foo'.
hasen j
2010-08-31 00:40:54
+1
A:
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"
slomojo
2010-08-31 00:55:15
A:
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'
icco
2010-08-31 01:15:55