How to search website files for text using cPanel Terminal

Search another help topic

You can use cPanel Terminal to find text inside your website files. This is useful for locating an old domain name, an email address or a particular piece of code.

The examples below use grep, a command that searches file contents. A recursive search checks the selected folder and its subfolders. These commands do not change your files.

1. Open cPanel Terminal

  1. Follow our guide to open cPanel Terminal.
  2. Choose the search command below for your main website or addon domain.
  3. Replace the example text and folder path with your own values.
  4. Paste the command into Terminal and press Enter.

Keep the single quotation marks around your search text. Copy only the code, without the Markdown backticks.

2. Search public_html

To search your main website’s public_html folder and all its subfolders:

grep -rInF -- 'text to find' "$HOME/public_html"

For example, to find references to an old domain:

grep -rInF -- 'old-domain.example' "$HOME/public_html"

The options mean:

Option Purpose
-r Search folders recursively.
-I Skip files detected as binary, such as many images and archives.
-n Show the line number of each match.
-F Treat the search text literally, rather than as a regular expression.

The -- separates command options from your search text. $HOME points to your hosting account’s home folder.

3. Search an addon domain

An addon domain may store its files outside public_html. Check its document root, which is the folder containing that domain’s website files.

  1. Open Domains in cPanel.
  2. Find your addon domain.
  3. Note the folder shown under Document Root.
  4. Use that folder in your search command.

For example, if the document root is example.com inside your account’s home folder:

grep -rInF -- 'text to find' "$HOME/example.com"

Use the actual document root shown in cPanel. Do not assume the folder matches your domain name.

Understand the results

A matching result looks like this:

/home/username/public_html/contact.php:24:Email us at hello@example.com

This shows the file path, line number and matching line of text. You can open the file in File Manager to inspect it.

Results may contain private configuration values. Check them before sharing screenshots or copying output into a support request.

Useful search options

Ignore capitalisation

Add lowercase -i to match text regardless of capitalisation:

grep -rInFi -- 'contact us' "$HOME/public_html"

This finds both Contact Us and contact us.

Show matching filenames only

Use -l if you only need a list of files containing the text:

grep -rIlF -- 'old-domain.example' "$HOME/public_html"

Search PHP files only

Use --include to limit the search to a particular file type:

grep -rInF --include='*.php' -- 'text to find' "$HOME/public_html"

Skip cache and backup folders

Exclude folders that do not need searching:

grep -rInF --exclude-dir=cache --exclude-dir=backups -- 'text to find' "$HOME/public_html"

Change the excluded folder names to match your website.

Troubleshooting

No results appear

The search may still be running. When the Terminal prompt returns, no output usually means no matches were found in the readable text files searched.

Check the spelling, try the case-insensitive example and confirm you selected the correct website folder.

“No such file or directory” appears

The search path is incorrect or the folder does not exist. Check the domain’s Document Root in cPanel.

“Permission denied” appears

Your account cannot read a file or folder. Contact our support team so we can investigate.

The search takes too long

Press Ctrl+C to stop it. Search a smaller folder or limit the file types, especially on large websites.

Can this search my WordPress database?

No. These commands search files, not database records such as published WordPress content and settings.

If you need help finding a particular reference, contact our support team. We can help you identify where to search.

Related articles

Need help with this?

Open a ticket and link to this guide so our team can see what you have tried.

View support tickets

Power your business with Ecenica Hosting

Built for WordPress and serious websites. Fast, secure and supported by real people in the UK.

Ecenica hosting services represented by a connected red route across London