{"id":59103,"date":"2023-11-16T15:01:25","date_gmt":"2023-11-16T07:01:25","guid":{"rendered":"https:\/\/www.hongkiat.com\/blog\/?p=59103"},"modified":"2023-11-15T18:58:29","modified_gmt":"2023-11-15T10:58:29","slug":"linux-command-grep","status":"publish","type":"post","link":"https:\/\/www.hongkiat.com\/blog\/linux-command-grep\/","title":{"rendered":"How to Use the Grep Command in Linux"},"content":{"rendered":"<p>In the world of Linux, searching through text files to find specific content is a common task, and one that can be achieved efficiently with the <code>grep<\/code> command. Short for \u201cGlobal Regular Expression Print,\u201d <code>grep<\/code> is a powerful command-line tool that allows users to search through files using patterns defined by regular expressions.<\/p>\n<p>Whether you\u2019re looking for a particular error in a log file, or trying to locate all instances of a specific term in a large codebase, <code>grep<\/code> is the go-to tool for text searching and manipulation. With the ability to match complex patterns, filter results, and even perform operations across multiple files, <code>grep<\/code> stands as a vital utility for system administrators, programmers, and data analysts alike.<\/p>\n<p>General syntax for <code>grep<\/code> command:<\/p>\n<pre>\r\n$ grep [OPTIONS...] [PATTERN] [FILE...]\r\n<\/pre>\n<hr>\n<h3>1. Search for something within a file<\/h3>\n<pre>grep exp FileName.txt<\/pre>\n<p><code>grep<\/code> is a powerful command that allows you to search for a specific set of characters, or words exist in a file, or multiple files. The command above search for <code>exp<\/code> within <code>FileName.txt<\/code>, and return results when found.<\/p>\n<p><strong>Note:<\/strong> <code>grep<\/code> is by default <strong>case-sensitive<\/strong>, and without other parameters involved, <code>grep<\/code> would return results as long as it matches \u201cexp\u201d.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<p>Assuming that <code>FileName.txt<\/code> contains the following text:<\/p>\n<pre>This is an example file.\r\nThe word exp is here.\r\nNo match in this line.\r\nExpression is a good word.\r\nExperience teaches wisdom.\r\n<\/pre>\n<p>The command <code>grep exp FileName.txt<\/code> would result in the following output:<\/p>\n<pre>This is an example file.\r\nThe word exp is here.\r\nExpression is a good word.\r\nExperience teaches wisdom.\r\n<\/pre>\n<p>This output displays all the lines in <code>FileName.txt<\/code> that contain the substring \u201cexp\u201d.<\/p>\n<hr>\n<h3>2. Search for something in multiple files<\/h3>\n<pre>grep all name1.txt name2.txt name3.txt<\/pre>\n<p>This command expands searching to multilple specified filenames.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<p>The command <code>grep all name1.txt name2.txt name3.txt<\/code> uses <code>grep<\/code> to search for the string \u201call\u201d within the files <code>name1.txt<\/code>, <code>name2.txt<\/code>, and <code>name3.txt<\/code>. If the string is found, it will print the lines containing that string along with the file names.<\/p>\n<pre>name1.txt:We are all in this together.\r\nname2.txt:All the best for your future.\r\nname3.txt:all of these lines match.\r\nname3.txt:All is well.\r\n<\/pre>\n<hr>\n<h3>3. Finding an exact word with <code>grep<\/code><\/h3>\n<pre>grep -w example Example.txt<\/pre>\n<p>With the <code>-w<\/code> parameter, <code>grep<\/code> gets more precise in its search and only <strong>return true if the exact word matches<\/strong>. In the command above, <code>grep<\/code> search for \"<strong>example<\/strong>\" in <code>Example.txt<\/code>.<\/p>\n<p>Any of the following would return false:<\/p>\n<ul>\n<li><code>E<\/code>xample<\/li>\n<li>example<code>s<\/code><\/li>\n<\/ul>\n<hr>\n<h3>4. Case-insensitive search with <code>grep<\/code><\/h3>\n<pre>grep -i being ExampleFile.txt<\/pre>\n<p>With the <code>-i<\/code> parameter, <code>grep<\/code> will search in a case-insensitive manner and will return true as long the input matches, regardles if it\u2019s lowercase or uppercase characters.<\/p>\n<p>The command above searches for the word \"<strong>being<\/strong>\" in <code>ExampleFile.txt<\/code>, and will return result if found.<\/p>\n<p>All the following will return true with existence of <code>-i<\/code>:<\/p>\n<ul>\n<li>\"<code>B<\/code>eing\"<\/li>\n<li>\"be<code>ING<\/code>\"<\/li>\n<\/ul>\n<hr>\n<h3>5. Count and output word repeatation with <code>grep<\/code><\/h3>\n<pre>grep -c smallness TextFile.txt<\/pre>\n<p>With the <code>-c<\/code> parameter, <code>grep<\/code> will first find if a specific word exist, and then count how many times it\u2019s being repeated. The command above search for \"<strong>smallness<\/strong>\" and return the number of times it existed in <code>TextFile.txt<\/code>.<\/p>\n<p>Here\u2019s a hypothetical sample output for the given command:<\/p>\n<pre>5\r\n<\/pre>\n<p>This would mean that the word \u201csmallness\u201d was found in 5 lines within the <code>TextFile.txt<\/code> file. If the word \u201csmallness\u201d is not found in the file at all, the command would output:<\/p>\n<pre>0\r\n<\/pre>\n<hr>\n<h3>6. Inverse search with <code>grep<\/code><\/h3>\n<pre>grep -v lorem sometext.txt<\/pre>\n<p>The parameter <code>-v<\/code> excludes the entire line that matches the input pattern, and output the rest that doesn\u2019t contain it. The command above searches for \"<strong>lorem<\/strong>\" in <code>sometext.txt<\/code>. Any lines without \"<strong>lorem<\/strong>\" will return true.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<p>Imagine <code>sometext.txt<\/code> contains the following lines:<\/p>\n<pre>lorem ipsum dolor sit amet\r\nconsectetur adipiscing elit\r\nlorem sed do eiusmod tempor\r\n<\/pre>\n<p>When you run the command <code>grep -v 'lorem' sometext.txt<\/code>, the output would be:<\/p>\n<pre>consectetur adipiscing elit\r\n<\/pre>\n<p>This line is the only one that does not contain the word \u201clorem.\u201d<\/p>\n<hr>\n<h3>7. Display matching line and list line number<\/h3>\n<pre>grep -n ipsum randomtext.txt<\/pre>\n<p>The parameter <code>-n<\/code> returns content with line-count. When a search word is included, it returns the entire line (where word exists) with its line-count. The command above search for \"<strong>ipsum<\/strong>\" in <code>randomtext.txt<\/code>, and its output shows which line \"<strong>ipsum<\/strong>\" is at.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<p>Assuming that <code>randomtext.txt<\/code> has the following content:<\/p>\n<pre>Lorem ipsum dolor sit amet, consectetur adipiscing elit.\r\nAnother line without the search term.\r\nYet another line.\r\nipsum ipsum ipsum\r\nHere's an ipsum too.\r\n<\/pre>\n<p>The command <code>grep -n ipsum randomtext.txt<\/code> would produce:<\/p>\n<pre>1:Lorem ipsum dolor sit amet, consectetur adipiscing elit.\r\n4:ipsum ipsum ipsum\r\n5:Here's an ipsum too.\r\n<\/pre>\n<p>Here, the numbers before the colons represent the line numbers in the file where the string \u201cipsum\u201d was found.<\/p>\n<hr>\n<h3>8. List filenames that contain matched string<\/h3>\n<pre>grep -l dolor *txt<\/pre>\n<p>With the <code>-l<\/code> parameter, only <code>.txt<\/code> extension files that contain the word \"<strong>dolor<\/strong>\" will return true. Filenames will be printed instead of the entire lioe.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<p>Assuming you have three files in the directory, namely <code>file1.txt<\/code>, <code>file2.txt<\/code>, and <code>file3.txt<\/code>, and \u201cdolor\u201d is found in <code>file1.txt<\/code> and <code>file3.txt<\/code>, the output would look like this:<\/p>\n<pre>file1.txt\r\nfile3.txt\r\n<\/pre>\n<hr>\n<h3>9. Search lines starting with a pattern<\/h3>\n<pre>grep ^Example TextFile.txt<\/pre>\n<p>The character <code>^<\/code> in front of a search-pattern suggests <code>grep<\/code> should only look words that starts with the search-pattern and nothing else. The command above will search in <code>TextFile.txt<\/code>, and return all lines that begins with \"<strong>Example<\/strong>\".<\/p>\n<p><strong>Example:<\/strong><\/p>\n<p>Assuming <code>TextFile.txt<\/code> contains the following text:<\/p>\n<pre>Example line 1\r\nThis is another line\r\nExample line 2\r\nYet another line without the keyword\r\nExample line 3\r\n<\/pre>\n<p>The output of the command would be:<\/p>\n<pre>Example line 1\r\nExample line 2\r\nExample line 3\r\n<\/pre>\n<hr>\n<h3>10. Multiple pattern search with <code>grep<\/code><\/h3>\n<pre>grep -e lorem -e amet ExampleFile.txt<\/pre>\n<p>The <code>-e<\/code> parameter can be used multiple times in the same command; each paired with a search-pattern, allows you to be more specific in searching for something in a file. The command above searches for the words \"<strong>lorem<\/strong>\", and \"<strong>amet<\/strong>\" in <code>ExampleFile.txt<\/code>, and return if true\/found.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<p>Assume <code>ExampleFile.txt<\/code> contains the following lines:<\/p>\n<pre>lorem ipsum dolor sit amet\r\nconsectetur adipiscing elit\r\namet, consectetur adipiscing\r\nsed do eiusmod tempor\r\nlorem incididunt ut\r\n<\/pre>\n<p>Running the command <code>grep -e lorem -e amet ExampleFile.txt<\/code> would output:<\/p>\n<pre>lorem ipsum dolor sit amet\r\namet, consectetur adipiscing\r\nlorem incididunt ut\r\n<\/pre>\n<hr>\n<h3 style=\"padding-bottom:10px\">More Linux commands:<\/h3>\n<table>\n<tbody>\n<tr>\n<td width=\"150\">Directory Operations<\/td>\n<td><a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-rm-rmdir\/\"><code>rmdir<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-cd\/\"><code>cd<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-pwd\/\"><code>pwd<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-exa\/\"><code>exa<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-ls\/\"><code>ls<\/code><\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"150\">File Operations<\/td>\n<td><a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-cat\/\"><code>cat<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-cp\/\"><code>cp<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-dd\/\"><code>dd<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-less\/\"><code>less<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-touch\/\"><code>touch<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-ln\/\"><code>ln<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-rename\/\"><code>rename<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-more\/\"><code>more<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-head\/\"><code>head<\/code><\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"150\">File System Operations<\/td>\n<td><a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-chown\/\"><code>chown<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-mkfs\/\"><code>mkfs<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-locate\/\"><code>locate<\/code><\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"150\">Networking<\/td>\n<td><a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-ping\/\"><code>ping<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-curl\/\"><code>curl<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-wget\/\"><code>wget<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-iptables\/\"><code>iptables<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-mtr\/\"><code>mtr<\/code><\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"150\">Search and Text Processing<\/td>\n<td><a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-find\/\"><code>find<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-grep\/\"><code>grep<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-sed\/\"><code>sed<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-whatis\/\"><code>whatis<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-ripgrep\/\"><code>ripgrep<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-fd\/\"><code>fd<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-tldr\/\"><code>tldr<\/code><\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"150\">System Information and Management<\/td>\n<td><a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-env\/\"><code>env<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-history\/\"><code>history<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-top\/\"><code>top<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-who\/\"><code>who<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-htop\/\"><code>htop<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-glances\/\"><code>glances<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-lsof\/\"><code>lsof<\/code><\/a><\/td>\n<\/tr>\n<tr>\n<td width=\"150\">User and Session Management<\/td>\n<td><a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-screen\/\"><code>screen<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-su\/\"><code>su<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-sudo\/\"><code>sudo<\/code><\/a> \u00b7 <a href=\"https:\/\/www.hongkiat.com\/blog\/linux-command-open\/\"><code>open<\/code><\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>","protected":false},"excerpt":{"rendered":"<p>In the world of Linux, searching through text files to find specific content is a common task, and one that can be achieved efficiently with the grep command. Short for \u201cGlobal Regular Expression Print,\u201d grep is a powerful command-line tool that allows users to search through files using patterns defined by regular expressions. Whether you\u2019re&hellip;<\/p>\n","protected":false},"author":9,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3397],"tags":[888,3316],"topic":[],"class_list":["entry-content","is-maxi"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v22.8 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>How to Use the Grep Command in Linux - Hongkiat<\/title>\n<meta name=\"description\" content=\"In the world of Linux, searching through text files to find specific content is a common task, and one that can be achieved efficiently with the grep\" \/>\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.hongkiat.com\/blog\/linux-command-grep\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Use the Grep Command in Linux\" \/>\n<meta property=\"og:description\" content=\"In the world of Linux, searching through text files to find specific content is a common task, and one that can be achieved efficiently with the grep\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.hongkiat.com\/blog\/linux-command-grep\/\" \/>\n<meta property=\"og:site_name\" content=\"Hongkiat\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/hongkiatcom\" \/>\n<meta property=\"article:published_time\" content=\"2023-11-16T07:01:25+00:00\" \/>\n<meta name=\"author\" content=\"Hongkiat.com\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@hongkiat\" \/>\n<meta name=\"twitter:site\" content=\"@hongkiat\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Hongkiat.com\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/linux-command-grep\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/linux-command-grep\\\/\"},\"author\":{\"name\":\"Hongkiat.com\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/person\\\/7cc686597d92f9086729e4bcc1577ba3\"},\"headline\":\"How to Use the Grep Command in Linux\",\"datePublished\":\"2023-11-16T07:01:25+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/linux-command-grep\\\/\"},\"wordCount\":768,\"publisher\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\"},\"keywords\":[\"Linux\",\"Linux Commands\"],\"articleSection\":[\"Desktop\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/linux-command-grep\\\/\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/linux-command-grep\\\/\",\"name\":\"How to Use the Grep Command in Linux - Hongkiat\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#website\"},\"datePublished\":\"2023-11-16T07:01:25+00:00\",\"description\":\"In the world of Linux, searching through text files to find specific content is a common task, and one that can be achieved efficiently with the grep\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/linux-command-grep\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/linux-command-grep\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/linux-command-grep\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Use the Grep Command in Linux\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\",\"name\":\"Hongkiat\",\"description\":\"Tech and Design Tips\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\",\"name\":\"Hongkiat.com\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/wp-content\\\/uploads\\\/hkdc-logo-rect-yoast.jpg\",\"contentUrl\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/wp-content\\\/uploads\\\/hkdc-logo-rect-yoast.jpg\",\"width\":1200,\"height\":799,\"caption\":\"Hongkiat.com\"},\"image\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/hongkiatcom\",\"https:\\\/\\\/x.com\\\/hongkiat\",\"https:\\\/\\\/www.pinterest.com\\\/hongkiat\\\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/person\\\/7cc686597d92f9086729e4bcc1577ba3\",\"name\":\"Hongkiat.com\",\"description\":\"This post is published by an HKDC (hongkiat.com) staff. (I.e., intern, staff writer, or editor).\",\"sameAs\":[\"https:\\\/\\\/www.hongkiat.com\"],\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/author\\\/com\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to Use the Grep Command in Linux - Hongkiat","description":"In the world of Linux, searching through text files to find specific content is a common task, and one that can be achieved efficiently with the grep","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.hongkiat.com\/blog\/linux-command-grep\/","og_locale":"en_US","og_type":"article","og_title":"How to Use the Grep Command in Linux","og_description":"In the world of Linux, searching through text files to find specific content is a common task, and one that can be achieved efficiently with the grep","og_url":"https:\/\/www.hongkiat.com\/blog\/linux-command-grep\/","og_site_name":"Hongkiat","article_publisher":"https:\/\/www.facebook.com\/hongkiatcom","article_published_time":"2023-11-16T07:01:25+00:00","author":"Hongkiat.com","twitter_card":"summary_large_image","twitter_creator":"@hongkiat","twitter_site":"@hongkiat","twitter_misc":{"Written by":"Hongkiat.com","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.hongkiat.com\/blog\/linux-command-grep\/#article","isPartOf":{"@id":"https:\/\/www.hongkiat.com\/blog\/linux-command-grep\/"},"author":{"name":"Hongkiat.com","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/person\/7cc686597d92f9086729e4bcc1577ba3"},"headline":"How to Use the Grep Command in Linux","datePublished":"2023-11-16T07:01:25+00:00","mainEntityOfPage":{"@id":"https:\/\/www.hongkiat.com\/blog\/linux-command-grep\/"},"wordCount":768,"publisher":{"@id":"https:\/\/www.hongkiat.com\/blog\/#organization"},"keywords":["Linux","Linux Commands"],"articleSection":["Desktop"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.hongkiat.com\/blog\/linux-command-grep\/","url":"https:\/\/www.hongkiat.com\/blog\/linux-command-grep\/","name":"How to Use the Grep Command in Linux - Hongkiat","isPartOf":{"@id":"https:\/\/www.hongkiat.com\/blog\/#website"},"datePublished":"2023-11-16T07:01:25+00:00","description":"In the world of Linux, searching through text files to find specific content is a common task, and one that can be achieved efficiently with the grep","breadcrumb":{"@id":"https:\/\/www.hongkiat.com\/blog\/linux-command-grep\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.hongkiat.com\/blog\/linux-command-grep\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.hongkiat.com\/blog\/linux-command-grep\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.hongkiat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Use the Grep Command in Linux"}]},{"@type":"WebSite","@id":"https:\/\/www.hongkiat.com\/blog\/#website","url":"https:\/\/www.hongkiat.com\/blog\/","name":"Hongkiat","description":"Tech and Design Tips","publisher":{"@id":"https:\/\/www.hongkiat.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.hongkiat.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.hongkiat.com\/blog\/#organization","name":"Hongkiat.com","url":"https:\/\/www.hongkiat.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.hongkiat.com\/blog\/wp-content\/uploads\/hkdc-logo-rect-yoast.jpg","contentUrl":"https:\/\/www.hongkiat.com\/blog\/wp-content\/uploads\/hkdc-logo-rect-yoast.jpg","width":1200,"height":799,"caption":"Hongkiat.com"},"image":{"@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/hongkiatcom","https:\/\/x.com\/hongkiat","https:\/\/www.pinterest.com\/hongkiat\/"]},{"@type":"Person","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/person\/7cc686597d92f9086729e4bcc1577ba3","name":"Hongkiat.com","description":"This post is published by an HKDC (hongkiat.com) staff. (I.e., intern, staff writer, or editor).","sameAs":["https:\/\/www.hongkiat.com"],"url":"https:\/\/www.hongkiat.com\/blog\/author\/com\/"}]}},"jetpack_featured_media_url":"https:\/\/","jetpack_shortlink":"https:\/\/wp.me\/p4uxU-fnh","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/59103","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/comments?post=59103"}],"version-history":[{"count":4,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/59103\/revisions"}],"predecessor-version":[{"id":68616,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/59103\/revisions\/68616"}],"wp:attachment":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/media?parent=59103"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/categories?post=59103"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/tags?post=59103"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/topic?post=59103"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}