How to search in multiple files or folders for a string inside a plain text file?
For example I need to find the string "foo" in all files in the folder "/home/thisuser/bar/baz/"
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With