从多个文件中查找一个字符串
平时在对日志的查找时,可能需要对多个日志进行一个字符串的查找,
用法: grep -rnisI 'foo' .
You need to have read privileges on the files you will be searching in. If you do have them, then simply use
grep -r "foo" /home/thisuser/bar/baz/*
to search in a certain folder or
grep "foo" /home/thisuser/bar/baz/somefile.txt
if you need to search in a specific file, in this case "somefile.txt". Basically the syntax is
grep [options] [searched string] [path]
// -r is an option which states that it will use recursive search
Another useful options are "-n" to show on which line in which file the string is located,
"-i" to ignore case,
"-s" to suppress some messages like "can't read file" or "not found" and
"-I" to ignore binary files.
If you use
grep -rnisI "foo" /home/thisuser/bar/baz/*
you will exactly know where to look.