Friday, 15 January 2010

search - Searching for a string in multiple files on Linux -


How to find a string inside a plain text file in multiple files or folders?

For example, in the folder "/ home / thisuser / bar / baz /"

You need to read the privileges on the files on which you will search. If you have such a thing, just use

  grep -r "foo" / home / thisuser / bar / Baz / *   

To search in a folder or

  grep "foo" /home/thisuser/bar/baz/somefile.txt   

if you have a specific file If there is a need to search, in this case "somefile.txt" is basically a syntax

  grep [options] [search string] [path] // -r is an option which states that This will use recursive search   

Another useful option "-n" shows how to File file is located in person, to ignore "-i", to suppress "-s" some messages like "file can not be read" or "not found" and "-i" binary files ignore To do.

If you use

  grep -rnisI "foo" / home / thisuser / bar / baz / *   

You will know exactly where to look.

No comments:

Post a Comment