Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Grep Linux command

Discussion in 'General Discussion' started by toplisek, Oct 27, 2017.

  1. toplisek

    toplisek Well-Known Member

    Joined:
    Jan 7, 2010
    Messages:
    124
    Likes Received:
    6
    Trophy Points:
    68
    I like to get logs and how is actually the correct way to do this?
    Example:

    grep /var/log/apache2/access.log
    grep /var/log/mysql/error.log
     
  2. rpvw

    rpvw Well-Known Member

    Joined:
    Jul 18, 2013
    Messages:
    691
    Likes Received:
    233
    Trophy Points:
    43
    Location:
    Spain
    cPanel Access Level:
    Root Administrator
    grep is a command-line utility for searching plain-text data sets for lines that match a regular expression.

    There are hundreds of example and tutorial sites for grep if you use your favorite search engine :)

    As an example, if I wanted to get all the lines in the /var/log/apache2/access_log that contained the string "mod.php?mod=downloads" , I could use a command like:
    Code:
    grep "mod.php?mod=downloads" /var/log/apache2/access_log
    This would output in my terminal potentially many lines of code, so I might pipe the output to a file instead eg
    Code:
    grep "mod.php?mod=downloads" /var/log/apache2/access_log > myfile
    then I can open or download myfile and deal with it at leisure :-D
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
    #2 rpvw, Oct 27, 2017
    Last edited: Oct 27, 2017
    cPanelMichael likes this.
  3. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    43,889
    Likes Received:
    1,814
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Hello,

    Let us know if you have any questions after reviewing the previous post.

    Thanks!
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice