{"id":226,"date":"2016-01-12T15:31:42","date_gmt":"2016-01-12T15:31:42","guid":{"rendered":"http:\/\/wp-p3d2tsa2xh.pairsite.com\/?p=226"},"modified":"2019-02-06T13:55:20","modified_gmt":"2019-02-06T18:55:20","slug":"paircloud-grep","status":"publish","type":"ht_kb","link":"https:\/\/www.pair.com\/support\/kb\/paircloud-grep\/","title":{"rendered":"Using grep"},"content":{"rendered":"<p class=\"p1\"><span class=\"s1\"><a style=\"color:#fff; text-decoration:none!important;\" href=\"https:\/\/www.pair.com\/support\/kb\/tags\/shared-hosting\/\"><p style=\"background-color:#1a3d6e !important;color:#fff;padding:6px; display:inline-block!important;font-size:12px;font-weight:bold; border-radius:3px;\">Shared<\/p><\/a> <a style=\"color:#fff; text-decoration:none!important;\" href=\"https:\/\/www.pair.com\/support\/kb\/tags\/vps\/\"><p style=\"background-color:#1a3d6e !important;color:#fff;padding:6px; display:inline-block!important;font-size:12px;font-weight:bold; border-radius:3px;\">VPS<\/p><\/a> <a style=\"color:#fff; text-decoration:none!important;\" href=\"https:\/\/www.pair.com\/support\/kb\/tags\/qs-dedicated\/\"><p style=\"background-color:#1a3d6e !important;color:#fff;padding:6px; display:inline-block!important;font-size:12px; font-weight:bold; border-radius:3px;\">Dedicated<\/p><\/a>\u00a0<a style=\"color:#fff; text-decoration:none!important;\" href=\"https:\/\/www.pair.com\/support\/kb\/tags\/wp-professional\/\"><p style=\"background-color:#1a3d6e !important;color:#fff !important;padding:6px; display:inline-block!important;font-size:12px;font-weight:bold; border-radius:3px;\">WP Professional<\/p><\/a> <a style=\"color:#fff; text-decoration:none!important;\" href=\"https:\/\/www.pair.com\/support\/kb\/tags\/wp-professional-plus\/\"><p style=\"background-color:#1a3d6e !important;color:#fff !important;padding:6px; display:inline-block!important;font-size:12px;font-weight:bold; border-radius:3px;\">WP Professional Plus<\/p><\/a><\/span><\/p>\n<h2>Introduction<\/h2>\n<p>Grep stands for Globally search a Regular Expression and Print. The basic usage of the command is <code>grep [options] expression filename<\/code>. Grep will by default display any lines in a file that contain the expression.<\/p>\n<h3 class=\"kb\">The Options<\/h3>\n<p>The main options we will use in this tutorial are <code>-P, -v, -i, -c, --color, -L, and -l<\/code>. The options will be covered in each of the following sections.<\/p>\n<h3 class=\"kb\">The -P option<\/h3>\n<p>There are four types of regex supported by grep. These are extended, fixed, basic and Perl. The -P option enables Perl Compartible Regular Expressions also known as PCRE. PCRE is the most commonly used regex and what our regex tutorial covers. In this tutorial, we will cover basic and PRCRE. If you are doing anything using PCRE then use\u00a0<code>grep -P \"expression\" filename<\/code>.<\/p>\n<h3 class=\"kb\">Reversing a match using -v<\/h3>\n<p>When running a grep match on a file you will sometimes want to exclude lines. To do this use grep -v \u201cexpression\u201d filename. For instance, if you want to view your Apache logs and exclude any googlebot lines you would use <code>grep -v \"googlebot\" \/var\/log\/httpd\/access_log<\/code>.<\/p>\n<h3 class=\"kb\">Case insensitive searches<\/h3>\n<p>The <code>-i<\/code> option allows you to do case insensitive searches. Using <code>grep -i \"SeArCh\" filename<\/code> will find any occurrence of the term \u201csearch\u201d no matter what the case.<\/p>\n<h3 class=\"kb\">Count the number of lines that match<\/h3>\n<p>If you are not interested in the lines that match, only the number of lines that match, then <code>-c<\/code> is the option to use. For example to find out how many times your <strong>wp-cron<\/strong> file has been called then <code>grep -c wp-cron \/var\/log\/httpd\/access_log<\/code> will give you that figure.<\/p>\n<h3 class=\"kb\">Setting color options<\/h3>\n<p>If you want the matches to be highlighted you can turn on the \u2013color option. On Ubuntu, it is on by default but on Centos is it off by default. To turn it on use <code>grep --color=always \"pattern\" filename<\/code>. To make this the default in Centos add this to your <strong>~\/.bashrc<\/strong> file:<\/p>\n<pre>alias grep='grep --color=auto'<\/pre>\n<h3 class=\"kb\">Matching and non-matching files<\/h3>\n<p>The <code>-l<\/code> and <code>-L<\/code> options return the filenames only when there is either no match present or there is a match present. This is not much use when just searching within one file for a pattern. However, if you are using the <code>find<\/code> command, for example, and it finds multiple files which you then run grep on, you may want just the file name returned of matching or non matching files. The <code>-L<\/code> option returns only filenames of files that have <strong>no<\/strong> match for the pattern and <code>-l<\/code> returns only the filenames of files that <strong>do<\/strong> have a match for the pattern.<\/p>\n<h3 class=\"kb\">Basic usage and using PCRE<\/h3>\n<p>If you just want to search for a basic string then you can use grep with no options. For example, if you want to search for lines that contain a specific IP in a log file then you would use <code>grep \"10.0.0.1\" filename<\/code>. If on the the other hand, you want to use the PCRE expression to find a range of IPs then you would need to use <code>grep -P \"^10.0.0.1[0-9][0-9]\" filename<\/code> which would find any matches with an IP between 10.0.0.100 and 10.0.0.199.<\/p>\n<p>Please see our tutorial on regex.<\/p>\n<h3 class=\"kb\">Conclusion<\/h3>\n<p>This covers the basic usage of grep, to find out more please see the man pages: <code>man grep<\/code>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0 Introduction Grep stands for Globally search a Regular Expression and Print. The basic usage of the command is grep [options] expression filename. Grep will by default display any lines in a file that contain the expression. The Options The main options we will use in this tutorial are -P,&#8230;<\/p>\n","protected":false},"author":12,"comment_status":"closed","ping_status":"open","template":"","format":"standard","meta":[],"ht-kb-category":[13],"ht-kb-tag":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.8.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Using grep - Knowledge Base - Pair Networks<\/title>\n<meta name=\"description\" content=\"Grep stands for &quot;Globally search a Regular Expression and Print.&quot; Learn about the basics of using this Unix command in this article.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.pair.com\/support\/kb\/paircloud-grep\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Using grep - Knowledge Base - Pair Networks\" \/>\n<meta property=\"og:description\" content=\"Grep stands for &quot;Globally search a Regular Expression and Print.&quot; Learn about the basics of using this Unix command in this article.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pair.com\/support\/kb\/paircloud-grep\/\" \/>\n<meta property=\"og:site_name\" content=\"Knowledge Base - Pair Networks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/pairnetworks\/\" \/>\n<meta property=\"article:modified_time\" content=\"2019-02-06T18:55:20+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@pairNetworks\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.pair.com\/support\/kb\/paircloud-grep\/\",\"url\":\"https:\/\/www.pair.com\/support\/kb\/paircloud-grep\/\",\"name\":\"Using grep - Knowledge Base - Pair Networks\",\"isPartOf\":{\"@id\":\"https:\/\/www.pair.com\/support\/kb\/#website\"},\"datePublished\":\"2016-01-12T15:31:42+00:00\",\"dateModified\":\"2019-02-06T18:55:20+00:00\",\"description\":\"Grep stands for \\\"Globally search a Regular Expression and Print.\\\" Learn about the basics of using this Unix command in this article.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.pair.com\/support\/kb\/paircloud-grep\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.pair.com\/support\/kb\/paircloud-grep\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.pair.com\/support\/kb\/paircloud-grep\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.pair.com\/support\/kb\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Using grep\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.pair.com\/support\/kb\/#website\",\"url\":\"https:\/\/www.pair.com\/support\/kb\/\",\"name\":\"Knowledge Base - Pair Networks\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/www.pair.com\/support\/kb\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.pair.com\/support\/kb\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.pair.com\/support\/kb\/#organization\",\"name\":\"Pair Networks\",\"url\":\"https:\/\/www.pair.com\/support\/kb\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pair.com\/support\/kb\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.pair.com\/support\/kb\/wp-content\/uploads\/2022\/02\/Gb_TUkUE_400x400.jpeg\",\"contentUrl\":\"https:\/\/www.pair.com\/support\/kb\/wp-content\/uploads\/2022\/02\/Gb_TUkUE_400x400.jpeg\",\"width\":360,\"height\":360,\"caption\":\"Pair Networks\"},\"image\":{\"@id\":\"https:\/\/www.pair.com\/support\/kb\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/pairnetworks\/\",\"https:\/\/twitter.com\/pairNetworks\",\"https:\/\/www.instagram.com\/pairnetworks\/\",\"https:\/\/www.linkedin.com\/company\/2269676\/\",\"https:\/\/www.pinterest.com\/pairnetworksinc\/pins\/\",\"https:\/\/www.youtube.com\/user\/pairnetworks\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Using grep - Knowledge Base - Pair Networks","description":"Grep stands for \"Globally search a Regular Expression and Print.\" Learn about the basics of using this Unix command in this article.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.pair.com\/support\/kb\/paircloud-grep\/","og_locale":"en_US","og_type":"article","og_title":"Using grep - Knowledge Base - Pair Networks","og_description":"Grep stands for \"Globally search a Regular Expression and Print.\" Learn about the basics of using this Unix command in this article.","og_url":"https:\/\/www.pair.com\/support\/kb\/paircloud-grep\/","og_site_name":"Knowledge Base - Pair Networks","article_publisher":"https:\/\/www.facebook.com\/pairnetworks\/","article_modified_time":"2019-02-06T18:55:20+00:00","twitter_card":"summary_large_image","twitter_site":"@pairNetworks","twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.pair.com\/support\/kb\/paircloud-grep\/","url":"https:\/\/www.pair.com\/support\/kb\/paircloud-grep\/","name":"Using grep - Knowledge Base - Pair Networks","isPartOf":{"@id":"https:\/\/www.pair.com\/support\/kb\/#website"},"datePublished":"2016-01-12T15:31:42+00:00","dateModified":"2019-02-06T18:55:20+00:00","description":"Grep stands for \"Globally search a Regular Expression and Print.\" Learn about the basics of using this Unix command in this article.","breadcrumb":{"@id":"https:\/\/www.pair.com\/support\/kb\/paircloud-grep\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pair.com\/support\/kb\/paircloud-grep\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.pair.com\/support\/kb\/paircloud-grep\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pair.com\/support\/kb\/"},{"@type":"ListItem","position":2,"name":"Using grep"}]},{"@type":"WebSite","@id":"https:\/\/www.pair.com\/support\/kb\/#website","url":"https:\/\/www.pair.com\/support\/kb\/","name":"Knowledge Base - Pair Networks","description":"","publisher":{"@id":"https:\/\/www.pair.com\/support\/kb\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pair.com\/support\/kb\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.pair.com\/support\/kb\/#organization","name":"Pair Networks","url":"https:\/\/www.pair.com\/support\/kb\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pair.com\/support\/kb\/#\/schema\/logo\/image\/","url":"https:\/\/www.pair.com\/support\/kb\/wp-content\/uploads\/2022\/02\/Gb_TUkUE_400x400.jpeg","contentUrl":"https:\/\/www.pair.com\/support\/kb\/wp-content\/uploads\/2022\/02\/Gb_TUkUE_400x400.jpeg","width":360,"height":360,"caption":"Pair Networks"},"image":{"@id":"https:\/\/www.pair.com\/support\/kb\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/pairnetworks\/","https:\/\/twitter.com\/pairNetworks","https:\/\/www.instagram.com\/pairnetworks\/","https:\/\/www.linkedin.com\/company\/2269676\/","https:\/\/www.pinterest.com\/pairnetworksinc\/pins\/","https:\/\/www.youtube.com\/user\/pairnetworks"]}]}},"_links":{"self":[{"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/ht-kb\/226"}],"collection":[{"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/ht-kb"}],"about":[{"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/types\/ht_kb"}],"author":[{"embeddable":true,"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/comments?post=226"}],"version-history":[{"count":8,"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/ht-kb\/226\/revisions"}],"predecessor-version":[{"id":6567,"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/ht-kb\/226\/revisions\/6567"}],"wp:attachment":[{"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/media?parent=226"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/ht-kb-category?post=226"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/ht-kb-tag?post=226"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}