12 Practical Examples of Linux grep Command

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.95/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...

19 Responses

  1. 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 #.
  2. saravana says:

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

  3. Vencen says:

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

  4. vikky says:

    how to use grep command?

  5. 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?

  6. Arpan Das says:

    Very useful. Thanks…

Got something to say? Join the discussion.

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