Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I search for a specific string (function name or a variable name) in my files which are in various directories under cPanel file manager?

I have been using a library directory and functions on that directory are used in various apps and pages. Now, I am in a situation to change something in the library file, for which I need to know the impact on files which use this library file functions.

How to search / find / grep through the files hosted?

share|improve this question
1  
I don't think you can through a cpanel (maybe a cron job set to run only once), but if you ssh to a server you can do it. – dkuntz2 Apr 18 '11 at 2:53
up vote 10 down vote accepted

I can understand the frustration when you don't have access to SSH. Below is a simple PHP script that you save in a file in the root folder from where you want to start your search. For example, I wanted to find all files that have the HEX color code string ecebeb under the ../public_html (or the www) folder. Retracing the steps here.

  1. Login to yourdomain/cpanel
  2. Go to File Manager - elect to go to www/public_html
  3. Create new file with .php extension - I created ecebeb.php - then edit it.
  4. Copy below 6 lines script, paste it in the ecebeb.php edit window and save the file.

    <?php
    $command = "grep -ri 'ecebeb' ./*";
    $output = shell_exec($command);
    echo "$output";
    echo "Grep job over.";
    ?>

  5. Now, open a new browser tab/window and browse to the URL like yourdomain/ecebeb.php

share|improve this answer
    
You will be happy to know that Cpanel has now added a search facility in the File Manager. – Sri Dec 19 '12 at 3:29
1  
@Sri Unfortunately it doesn't search within files, it only looks for file names. – CaptSaltyJack Feb 9 '15 at 20:59
    
I've used this code several times. Thank you @Sri. However, I'm trying to use it on a significantly larger website now, and I've been unsuccessful. In fact, the page just appears to be loading for a long period of time. Then, it comes back and says page could not be found. Does this code not work on large websites? – CQuinn Jan 20 at 19:09

AFAIK, it’s impossible. You must write a PHP/Perl/Python/whatever script and run it on your server to get the list of files and grep through it.

share|improve this answer

protected by John Conde Feb 9 at 16:59

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.