[linux] Linux : Search for a Particular word in a List of files under a directory

I have a big list of log files in a particular directory , related to my java Application under my Linux Remote Servers .

When i do ls on that particular directory it shows a list of files (nearly 100 files )

Now in that List of files , i need to find out a particular word , please tell me , how can i do this ??

The problem is that I cannot open each and every file and search for that word using /

Please tell me how can i search for a word in the list of files provided .

This question is related to linux

The answer is


You could club find with exec as follows to get the list of the files as well as the occurrence of the word/string that you are looking for

find . -exec grep "my word" '{}' \; -print

You are looking for grep command.

You can read 15 Practical Grep Command Examples In Linux / UNIX for some samples.


use this command grep "your word" searchDirectory/*.log

Get more on this link

http://www.cyberciti.biz/faq/howto-recursively-search-all-files-for-words/


This is a very frequent task in linux. I use grep -rn '' . all the time to do this. -r for recursive (folder and subfolders) -n so it gives the line numbers, the dot stands for the current directory.

grep -rn '<word or regex>' <location>

do a

man grep 

for more options


You can use this command:

grep -rn "string" *

n for showing line number with the filename r for recursive


also you can try the following.

find . -name '*.java' -exec grep "<yourword" /dev/null {} \;

It gets all the files with .java extension and searches 'yourword' in each file, if it presents, it lists the file.

Hope it helps :)