tags:

views:

53

answers:

3

Hi all. Using PHP, how to find all the files in the whole system (I am using ubuntu) which contain string errorlog. I tried exec() and grep but it is taking just one occurrence. Thanks.

+1  A: 

well using php it would need a routine that walkes the whole system, for example recursivly, open each file with a certain ending and then walk this file and watch every line for the appereance of the sting and when finding the string just save it somewhere.

BTW PHP isnt't the best candidate for searching the whole system for an appearance of a certain string. If possible i'd rather take another language that is a bit faster on handling system near tasks.

Under windows i use notepad++ as a Tool to search a certain folder with all its subfolders for all occurences of a certain string.

ITroubs
Notepad++ blocks the program while searching and shows no progress whatsoever. For this reason I prefer to use an alternative program for searching. They should really move it to a separate thread and show search progress or current search location.
manixrock
Yes i agree with that.
ITroubs
+1  A: 

You may use grep -R "errorlog" / to recursively search the all files on the system for the string 'errorlog'. Use the php exec command to do it from php.

Thariama
+1  A: 

Do you mean on the servers /*; or just a sub directory structure?

It does sound like you want to use shell out to find though.

http://www.athabascau.ca/html/depts/compserv/webunit/HOWTO/find.htm#EX03

(Searches pwd; i'd look into -maxdepth for performance reasons)

find . -exec grep "www.athabasca" '{}' \; -print
wom