开发者

unix bash command

How to write a bash command that finds all files in the current directo开发者_如何学Cry that contain the word “foo”, regardless of case?


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.


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"


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


Try:

echo *foo*

will print file/dir names matching *foo* in the current directory, which happens to match any name containing 'foo'.


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'


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜