Searching for a string in multiple files on Linux

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.

Tags:

Linux

Search

Grep