{"id":9018,"date":"2026-05-30T14:30:22","date_gmt":"2026-05-30T12:30:22","guid":{"rendered":"https:\/\/mybox.com\/help\/?post_type=manual_kb&#038;p=9018"},"modified":"2026-05-30T14:30:23","modified_gmt":"2026-05-30T12:30:23","slug":"ssh-commands-grep","status":"publish","type":"manual_kb","link":"https:\/\/mybox.com\/help\/en\/knowledgebase\/ssh-commands-grep\/","title":{"rendered":"SSH Commands &#8211; grep"},"content":{"rendered":"\n<div class=\"translation-block translation-block-merged\">\n<p class=\"wp-block-paragraph\">The <code>grep<\/code> command is used to search for specific text inside files. It helps you quickly find matching lines in logs, configuration files, or any text-based file when working through SSH.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It is commonly used in server administration to locate errors, settings, or patterns without opening files manually.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_86 ez-toc-wrap-left counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/mybox.com\/help\/en\/knowledgebase\/ssh-commands-grep\/#How_the_command_works\" >How the command works<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/mybox.com\/help\/en\/knowledgebase\/ssh-commands-grep\/#Common_usage_examples\" >Common usage examples<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/mybox.com\/help\/en\/knowledgebase\/ssh-commands-grep\/#Search_for_a_word_in_a_file\" >Search for a word in a file<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/mybox.com\/help\/en\/knowledgebase\/ssh-commands-grep\/#Case-insensitive_search\" >Case-insensitive search<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/mybox.com\/help\/en\/knowledgebase\/ssh-commands-grep\/#Show_line_numbers\" >Show line numbers<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/mybox.com\/help\/en\/knowledgebase\/ssh-commands-grep\/#Invert_match_exclude_results\" >Invert match (exclude results)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/mybox.com\/help\/en\/knowledgebase\/ssh-commands-grep\/#Count_occurrences\" >Count occurrences<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/mybox.com\/help\/en\/knowledgebase\/ssh-commands-grep\/#Searching_in_multiple_files\" >Searching in multiple files<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/mybox.com\/help\/en\/knowledgebase\/ssh-commands-grep\/#Practical_implications\" >Practical implications<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/mybox.com\/help\/en\/knowledgebase\/ssh-commands-grep\/#Summary\" >Summary<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_the_command_works\"><\/span>How the command works<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<\/div>\n\n<div id=\"mybox-3887393850\" class=\"mybox-content mybox-entity-placement\"><div class=\"early-access-banner-inpost\">\r\n  <div class=\"banner-left-inpost\">\r\n    <div class=\"icon-box-inpost\">\r\n      <img decoding=\"async\" src=\"https:\/\/mybox.com\/help\/wp-content\/uploads\/2026\/02\/square-info-icon.svg\" alt=\"Info\">\r\n    <\/div>\r\n    <div class=\"text-box-inpost\">\r\n      <span class=\"label-inpost\"><span class=\"translation-block translation-block-banner-text\">Early access<\/span><\/span>\r\n      <h4><span class=\"translation-block translation-block-banner-text\">Still need help?<\/span><\/h4>\r\n      <p><span class=\"translation-block translation-block-banner-text\">Contact our customer service team.<\/span><\/p>\r\n    <\/div>\r\n  <\/div>\r\n\r\n  <div class=\"banner-right-inpost\">\r\n    <a href=\"https:\/\/panel.mybox.com\/helpdesk2\/v\/list\/\" class=\"banner-button-inpost\"><span class=\"translation-block translation-block-banner-text\">Message us<\/span><\/a>\r\n  <\/div>\r\n<\/div><\/div>\n\n<div class=\"translation-block translation-block-merged\"><p class=\"wp-block-paragraph\">The basic structure of the command is:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>grep \"text\" file.txt<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This searches for the specified text inside a file and returns all lines that contain a match.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Common_usage_examples\"><\/span>Common usage examples<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Search_for_a_word_in_a_file\"><\/span>Search for a word in a file<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>grep \"error\" error.log<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This returns all lines containing the word <code>error<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Case-insensitive_search\"><\/span>Case-insensitive search<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>grep -i \"error\" error.log<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This finds matches regardless of uppercase or lowercase letters.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Show_line_numbers\"><\/span>Show line numbers<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>grep -n \"error\" error.log<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This displays matching lines together with their line numbers.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Invert_match_exclude_results\"><\/span>Invert match (exclude results)<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>grep -v \"debug\" log.txt<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This shows all lines that do not contain the word <code>debug<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Count_occurrences\"><\/span>Count occurrences<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>grep -c \"error\" log.txt<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This returns the number of matching lines.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Searching_in_multiple_files\"><\/span>Searching in multiple files<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You can also search across multiple files or entire directories:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>grep -r \"error\" \/path\/to\/directory<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>-r<\/code> option searches recursively through all subdirectories.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Practical_implications\"><\/span>Practical implications<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>grep<\/code> command is especially useful when:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>analyzing server logs<\/li>\n\n\n\n<li>debugging application errors<\/li>\n\n\n\n<li>searching configuration files<\/li>\n\n\n\n<li>filtering output from other commands<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">For large directories, recursive searches (<code>-r<\/code>) may take longer to complete depending on the number of files.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Summary\"><\/span>Summary<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>grep<\/code> command allows fast text searching inside files and directories. It is a core tool for working efficiently in a Linux environment through SSH.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"template":"","format":"standard","manualknowledgebasecat":[54],"manual_kb_tag":[1326,1519,5830,5833,5837,6118,6129,6159,6160,6161],"class_list":["post-9018","manual_kb","type-manual_kb","status-publish","format-standard","hentry","manualknowledgebasecat-ssh","manual_kb_tag-command-line","manual_kb_tag-grep","manual_kb_tag-grep-command","manual_kb_tag-text-search","manual_kb_tag-recursive-search","manual_kb_tag-linux-command","manual_kb_tag-command-line-tools","manual_kb_tag-grep-examples","manual_kb_tag-unix-command","manual_kb_tag-file-search"],"_links":{"self":[{"href":"https:\/\/mybox.com\/help\/en\/wp-json\/wp\/v2\/manual_kb\/9018","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mybox.com\/help\/en\/wp-json\/wp\/v2\/manual_kb"}],"about":[{"href":"https:\/\/mybox.com\/help\/en\/wp-json\/wp\/v2\/types\/manual_kb"}],"author":[{"embeddable":true,"href":"https:\/\/mybox.com\/help\/en\/wp-json\/wp\/v2\/users\/1"}],"version-history":[{"count":1,"href":"https:\/\/mybox.com\/help\/en\/wp-json\/wp\/v2\/manual_kb\/9018\/revisions"}],"predecessor-version":[{"id":9019,"href":"https:\/\/mybox.com\/help\/en\/wp-json\/wp\/v2\/manual_kb\/9018\/revisions\/9019"}],"wp:attachment":[{"href":"https:\/\/mybox.com\/help\/en\/wp-json\/wp\/v2\/media?parent=9018"}],"wp:term":[{"taxonomy":"manualknowledgebasecat","embeddable":true,"href":"https:\/\/mybox.com\/help\/en\/wp-json\/wp\/v2\/manualknowledgebasecat?post=9018"},{"taxonomy":"manual_kb_tag","embeddable":true,"href":"https:\/\/mybox.com\/help\/en\/wp-json\/wp\/v2\/manual_kb_tag?post=9018"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}