12 Practical Examples of Linux grep Command

Best Affordable Linux and WordPress Services For Your Business
Outsource Your Linux and WordPress Project and Get it Promptly Completed Remotely and Delivered Online.

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

Rob Krul

Rob is an avid user of Linux and Open Source Software, with over 15 years experience in the tech geek universe. Aside from experimenting with the many flavors of Linux, he enjoys working with BSDs, Solaris, and OS X. He currently works as an Independent IT Contractor.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

20 Responses

  1. ggx2 says:

    Your first example is an awesome choice! It’s exactly what I came here looking how to use grep to do.

  2. Nemanja says:

    The example number 2 is is VERY WRONG.

    # grep -v “#” /etc/apache2/sites-available/default-ssl

    will also exclude lines like: value display_errors off; # turns off errors right way to this is:

    # grep -v "^#"  /etc/apache2/sites-available/default-ssl
    so it will exclude only lines that begins with #.
  3. saravana says:

    i didn’t understand the differences between grep,egrep,fgrep. can anyone pls help me.

  4. Vencen says:

    In step 1 you use dpkg –l | grep –i python the –l part has a dash you should use a Hyphen.

  5. vikky says:

    how to use grep command?

  6. Mike says:

    Im new to grep, but i have found it very handy.

    I do allot of searching the same files every day and most of the time its a single file
    grep -i -A50 “diskview -j” *-Report* | less -R

    i have this alias that works great thought sometimes i am working on several systems at once and they all have the same file.
    I need to know what array i am looking at but i dont need it to print the file name for all 50 lines.

    So what i was trying to figure out is can i do a grep -i -l “diskview -j” *-Report*

    followed by my original grep command so i get the file name by it self followed by the diskview -j and the next 50 lines?

    Or is this going to produce 3 file names followed by 3 diskveiw -j reports?

  7. Arpan Das says:

    Very useful. Thanks…

Got something to say? Join the discussion.

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.