开发者

Find a string in all the files on the system

开发者 https://www.devze.com 2023-01-19 02:55 出处:网络
Using PHP, how to find all the files in the whole system (I am using ub开发者_JAVA技巧untu) which contain string errorlog.

Using PHP, how to find all the files in the whole system (I am using ub开发者_JAVA技巧untu) which contain string errorlog. I tried exec() and grep but it is taking just one occurrence. Thanks.


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.


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.


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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号