12 Practical Examples of Linux grep Command

If you have any questions or problems regarding this article and want help within 24 Hours? Ask Now

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.

Receive Your Free Complimentary eBook NOW! -

Download Free Linux eBooks

Advanced Bash-Scripting Guide
Linux Bible
A Newbie's Getting Started Guide to Linux
Ubuntu Linux Toolbox: 1000+ Commands

You may also like...

11 Responses

  1. willam Smith says:

    I hate Linux and we should ban it

  2. kl says:

    SUDO means Super User DO, we may not have privileges to execute a command. at that time we will use sudo to get the job done. :)

  3. Jim says:

    To count all occurrences of a pattern, try

    ifconfig | grep -o bytes | wc -l

    Compare the output against

    ifconfig | grep -c bytes

  4. beginner says:

    i think the example which u provided is not full proof which u mentioned in your point

    6. Count Number of Matches

    ifconfig | grep –c inet6

    this will only give the first occurrence of the word/pattern in every line and not all the matches.

    Can you please provide any other solution ??

    Regards
    Begineer

  5. Rob Krul says:

    I’m not sure why `sudo` is in there. I didn’t write the article that way, nor would I ever want anyone to use sudo on files if they don’t have to. Must have gotten inadvertently messed up when it went to print. I will contact the editors immediately.

  6. vasilisc says:

    much better

    sudo grep –vE “(#|^$)” /etc/apache2/sites-available/default-ssl

    remove blank line and comment

  7. iPenguin says:

    Why are you using sudo in all your examples?

  8. Darren says:

    nice list of practical uses of ‘grep’, I might use it in my class, however why are all the commands run with ‘sudo’? None of the commands listed should require ‘sudo’ to run properly (unless of course the user does not have permission to read/list the files in question, but that is beyond the scope of this article).

  9. mesuutt says:

    Good tips. Thanks @Rob.

  10. joni says:

    Apache config example (grep -v “#”) is a little dangerous. Unexpected will happen if a line contains # but does not start with it.

    Better could be grep -v ” *#”

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Join Over 75000+ Linux Users
  1. 51334
  2. 2657
  3. 16705

Enter your email to get latest Linux Howto's