How can I use grep to find a word inside a folder

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

I am just really new to using Linux, so this may sound really silly to you guys. So I request you to be patient with this beginner.

In Windows, I would have done a search for finding a word inside a folder. Similarly, I want to know if a specific word occurs inside a directory containing many sub-directories and files. My searches for grep syntax shows I must specify the filename, i.e. grep string filename.

Now, I do not know the filename, so what do I do? A friend suggested to do grep -nr string, but I don t know what this means and I got no results with it (there is no response until I issue a ctrl + c).

Answers

grep -nr  yourString*  .

The dot at the end searches the current directory. Meaning for each parameter:

-n            Show relative line number in the file
 yourString*  String for search, followed by a wildcard character
-r            Recursively search subdirectories listed
.             Directory for search (current directory)

grep -nr MobileAppSer* . (Would find MobileAppServlet.java or MobileAppServlet.class or MobileAppServlet.txt; MobileAppASer*.* is another way to do the same thing.)

To check more parameters use man grep command.

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/4121803/how-can-i-use-grep-to-find-a-word-inside-a-folder

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils