Centurion
Centurion

Reputation: 5291

Find a string in all the files on the system

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.

Upvotes: 1

Views: 249

Answers (3)

wom
wom

Reputation: 436

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

Upvotes: 1

Thariama
Thariama

Reputation: 50830

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.

Upvotes: 1

ITroubs
ITroubs

Reputation: 11215

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.

Upvotes: 1

Related Questions