Ask Steves · Daily notes · VPS, 20% off · AI Profit Lab · SEO · Money Hub

13 October 2026 · One command a day

How do I search inside files for text on Linux?

The grep -r command searches the text inside every file under a folder and prints each line that matches. Adding --include limits the search to one type of file, such as config files. You reach for it when you know a setting exists somewhere on the server but not which file it is in.

I learn my automation tips in the AI Profit Boardroom. Have a look here. Affiliate link.

The command

grep -r "search term" /path --include="*.conf"

grep prints lines that match a pattern. -r means recursive, so it looks in the folder you give and every folder below it. "search term" is the text to look for. Keep it in quotes if it has spaces or symbols. /path is where to start, for example /etc/nginx. --include="*.conf" tells grep to only open files whose names end in .conf. The quotes stop the shell from expanding the * before grep sees it. A real example looks like this:

grep -r "server_name" /etc/nginx --include="*.conf"

What you will see

/etc/nginx/conf.d/sitename.conf:    server_name example.com www.example.com;
/etc/nginx/sites-available/appname.conf:    server_name app.example.com;
/etc/nginx/nginx.conf:	# server_names_hash_bucket_size 64;

Each line starts with the path of the file, then a colon, then the full line that matched. The last result shows that grep matches text anywhere in a line, so server_name also matches server_names_hash_bucket_size, even inside a comment. If nothing matches, grep prints nothing and exits quietly.

When to use it

Watch out for

On Ubuntu, the files in /etc/nginx/sites-available often have no extension at all. The default site is simply called default. With --include="*.conf", grep skips those files without telling you, so it can look as if a setting is not there when it is. If you get no results where you expect some, run the search again without --include.

Questions people ask

How do I show the line number of each match?

Add -n, as in grep -rn "search term" /path --include="*.conf". Each result then shows the file, the line number and the line.

Why do I get "Permission denied" errors?

Some folders, such as /etc/letsencrypt, can only be read by root. Run the command with sudo at the front, or add -s to hide the error messages.

Searching through a server's own config files like this is only possible on a server you control. You can get the same VPS with 20% off at https://asksteves.co.uk/vps. Affiliate link.

Want more automation tips? The AI Profit Boardroom on Skool is where I get mine. Have a look here. Affiliate link.

Everything on this blog runs on one Hostinger KVM 8. This link takes 20% off the same box.

GET A VPS, 20% OFF →

Affiliate link.

Related server notes: How do I find world-writable files on my Linux web server? · How do I find what is using disk space on Linux? · How do I count matching lines in a log file on Linux? · All daily notes