How to Use the Grep Command to Find Information in Files

ABHILASH CA

Junior Devops Engineer

Last Updated: 16 October 2026
How to Use the Grep Command to Find Information in Files
🖥️12,400+PCs Fixed
⭐4.9★Google Rating
⚡<15 minAvg. Response
🛡️ISO 27001Certified

Search for a word in a file

If you have a file called cloudhouse.txt and you want to find all lines containing the word Python, you can use:

grep "grep" cloudhouse.txt

💡 None of these worked? Skip the guesswork.

Get Expert Help →

Commonly Used grep Options

1Case insensitive search

The -i option enables to search for a string case insensitively in the given file. It matches the words like "grep", "Grep", "gRep".

grep -i "Grep" geekfile.txt
  1. Displaying the Count Matches Using grep

We can find the number of lines that matches the given string/pattern

grep -c "grep" clouhouse.txt
3Display the Matching Filenames Using grep

We can just display the files that contains the given string/pattern.

grep -l "grep" *
4Checking Whole Words Using grep

By default, grep matches the given string/pattern even if it is found as a substring in a file. The -w option to grep makes it match only the whole words.

grep -w "grep" cloudhouse.txt
5Display Matched Pattern Using grep

By default, grep displays the entire line which has the matched string. We can make the grep to display only the matched string by using the -o option.

grep -o "grep" cloudhouse.txt
6Show Line Numbers with grep -n

To show the line number of file with the line matched.

grep -n "grep" cloudhouse.txt
7Inverting the Pattern Match Using grep

You can display the lines that are not matched with the specified search string pattern using the -v option.

grep -v "grep" cloudhouse.txt
8Match Lines Starting with a String using grep

The ^ regular expression pattern specifies the start of a line. This can be used in grep to match the lines which start with the given string or pattern.

grep "^grep" cloudhouse.txt

Conclusion

The grep command is a powerful and essential tool for searching text within files on Linux systems. By understanding its basic syntax and commonly used options, you can quickly locate specific information, troubleshoot issues, and analyze logs more efficiently. Whether you are a beginner or an experienced Linux user, mastering grep will significantly improve your productivity and command-line skills.

Related service: Server Management Service - Managed Linux and Windows servers: monitoring, patching, security and 24/7 support.

Text SearchLinux Commands

Get the Free Linux Server Admin Cheatsheet (PDF)

Essential commands for server management, networking, and troubleshooting — all on one printable page.

Running Linux servers? Let us manage them for you.

Our Managed Linux Server plans cover updates, security hardening, monitoring, and 24/7 incident response — so your servers stay up and your team stays focused.

  • Proactive OS patching and security updates
  • 24×7 monitoring with instant alerting
  • Backup configuration and disaster recovery
  • Dedicated Linux engineers on call
See Pricing Plans →

What our customers say

“Our production server went down at 2 AM. CloudHouse had it back online in under 20 minutes. Incredible response time.”

Arun S.

CTO, SaaS Startup

“They migrated our entire infrastructure from Ubuntu 18 to 22 with zero downtime. Couldn't have asked for better.”

Deepak N.

DevOps Lead

Frequently Asked Questions

Yes — 90% of fixes are done over a secure remote session in 15–30 minutes. Our technicians connect safely using industry-standard tools.

Need this done for you?

Server Management Service

Managed Linux and Windows servers: monitoring, patching, security and 24/7 support.

Learn more

Book your free 15-minute diagnosis

A certified technician will call you back within 15 minutes during business hours.

Share this article

Leave a Comment

Comments (0)

Loading comments...