Skip to content
  • About
  • Courses
  • ResearchExpand
    • Research Publications
    • Books
    • Patents
  • Workshop/Conferences
  • ToolsExpand
    • Creative Image Converter
    • Creative QRCode Generator
    • Creative QR Code Generator Tool
    • EMI Calculator
    • SIP Calculator
  • Blog
  • Resume
Download CV
Unix

grep Command

The grep Command

The grep command searches a file or files for lines that have a certain pattern.

Syntax

$grep pattern file(s)

Options

Sr. No.Option & Description
1.-v (Prints all lines that do not match pattern.)
2.-n (Prints the matched line and its line number.)
3.-l (Prints only the names of files with matching lines (letter “l”))
4.-c (Prints only the count of matching lines.)
5-i (Matches either upper or lowercase.)

Example

[nishant@localhost ~]$ ls -l
total 104
-rw-r–r–. 1 root root 44013 Aug 31 13:40 cwp2-latest
drwxr-xr-x. 3 nishant nishant 4096 Oct 14 2019 Desktop
drwxr-xr-x. 2 nishant nishant 4096 Jan 20 2015 Documents
drwxr-xr-x. 2 nishant nishant 4096 Jan 20 2015 Downloads
-rw-r–r–. 1 root root 14540 Nov 5 2012 epel-release-6-8.noarch.rpm
-rw-rw-r–. 1 nishant nishant 413 Aug 29 2016 file
-rwxrwxr-x. 1 vikas nishant 2033 Aug 29 2016 file1
drwxr-xr-x. 2 nishant nishant 4096 Jan 20 2015 Music
-rw-rw-r–. 1 nishant nishant 57 Aug 29 2016 newfile
drwxr-xr-x. 2 nishant nishant 4096 Jan 20 2015 Pictures
drwxr-xr-x. 2 nishant nishant 4096 Jan 20 2015 Public
drwxr-xr-x. 2 nishant nishant 4096 Jan 20 2015 Templates
drwxr-xr-x. 2 nishant nishant 4096 Jan 20 2015 Videos

In the above result, it is clear that there are files created in August, January, October but if need to search files from January only, then we can use “grep” command along with the “pipes” command like as below.

[nishant@localhost ~]$ ls -l | grep “Jan”
drwxr-xr-x. 2 nishant nishant 4096 Jan 20 2015 Documents
drwxr-xr-x. 2 nishant nishant 4096 Jan 20 2015 Downloads
drwxr-xr-x. 2 nishant nishant 4096 Jan 20 2015 Music
drwxr-xr-x. 2 nishant nishant 4096 Jan 20 2015 Pictures
drwxr-xr-x. 2 nishant nishant 4096 Jan 20 2015 Public
drwxr-xr-x. 2 nishant nishant 4096 Jan 20 2015 Templates
drwxr-xr-x. 2 nishant nishant 4096 Jan 20 2015 Videos

grep Search from file

[nishant@localhost question]$ grep Musa banana.txt
Banana (Musa species) is an important fruit of tropics.
It may be one of the reasons why the banana is called Apple of Paradise and botanically named Musa paradisiaca.

In the above example the word “Musa” was search from the file “banana.txt” and the word has been found in two lines in the file, so the grep command displays only those two line from the file.

Post navigation

Previous Previous
Shell Case Statement
NextContinue
Unix Comparison Operator
Latest

🎓 Why Original Work Matters in Your Final Year Project (And How It Can Shape Your Career)

In engineering colleges across the country, final year projects are often treated as just another academic task. But what many students fail to realize is…

Read More 🎓 Why Original Work Matters in Your Final Year Project (And How It Can Shape Your Career)Continue

Latest

🎓 How to Choose Your Final Year Project: A Practical Guide for BTech Students

Choosing the right final year project is one of the most important decisions of your engineering journey. It’s more than just a submission — it’s…

Read More 🎓 How to Choose Your Final Year Project: A Practical Guide for BTech StudentsContinue

Latest

🧠 MCP Server: Model Context Prototyping with Gemini + MySQL + FastAPI

GitHub: https://github.com/nishantmunjal2003/mcp-server-gemini 📌 Project Overview MCP Server is a lightweight, extendable API server that: ⚙️ Features 📁 Folder Structure bashCopyEditmcp-server/ │ ├── app.py # Main…

Read More 🧠 MCP Server: Model Context Prototyping with Gemini + MySQL + FastAPIContinue

Artificial Intelligence Psychology

Why You Can’t Stop Scrolling — And What AI Has to Do With It

Ever caught yourself reaching for your phone, telling yourself it’s “just for a minute”… and then suddenly it’s midnight?You didn’t mean to spend the last…

Read More Why You Can’t Stop Scrolling — And What AI Has to Do With ItContinue

Latest

Advance AI PPT

Read More Advance AI PPTContinue

Nishant Munjal

Coding Humanity’s Future </>


Facebook Twitter Linkedin YouTube Github Email

Tools

  • SIP Calculator
  • EMI Calculator
  • Creative QR Code
  • Image Converter

Resources

  • Blog
  • Contact
  • Refund and Returns

Legal

  • Disclaimer
  • Privacy Policy
  • Terms and Conditions

© 2025 - All Rights Reserved

  • About
  • Courses
  • Research
    • Research Publications
    • Books
    • Patents
  • Workshop/Conferences
  • Tools
    • Creative Image Converter
    • Creative QRCode Generator
    • Creative QR Code Generator Tool
    • EMI Calculator
    • SIP Calculator
  • Blog
  • Resume
Download CV
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.