{"id":12744,"date":"2025-06-09T06:44:53","date_gmt":"2025-06-09T06:44:53","guid":{"rendered":"https:\/\/hostnoc-revamp.branex.org\/blog\/?p=12744"},"modified":"2025-06-12T06:45:56","modified_gmt":"2025-06-12T06:45:56","slug":"prep-command-in-linux","status":"publish","type":"post","link":"https:\/\/hostnoc-revamp.branex.org\/blog\/prep-command-in-linux\/","title":{"rendered":"Prep Command in Linux: All You Need To Know"},"content":{"rendered":"<h3><b>Prep Command in Linux <\/b><\/h3>\n<h3><b>Basic Syntax<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">The general syntax for <\/span><span style=\"font-weight: 400;\">grep<\/span><span style=\"font-weight: 400;\"> is:<\/span><\/p>\n<p><b>grep [OPTIONS] PATTERN [FILE&#8230;]<\/b><\/p>\n<p><span style=\"font-weight: 400;\">This command searches for the specified <\/span><b>PATTERN<\/b> <span style=\"font-weight: 400;\">in the given <\/span><b>FILE<\/b> <span style=\"font-weight: 400;\">or from standard input.<\/span><\/p>\n<h3><b>Commonly Used Options<\/b><\/h3>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">-i<\/span><span style=\"font-weight: 400;\">: Performs a case-insensitive search.<\/span>&nbsp;<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">-v<\/span><span style=\"font-weight: 400;\">: Inverts the match to select non-matching lines.<\/span>&nbsp;<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">-n<\/span><span style=\"font-weight: 400;\">: Displays line numbers along with matching lines.<\/span>&nbsp;<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">-r<\/span><span style=\"font-weight: 400;\"> or <\/span><span style=\"font-weight: 400;\">-R<\/span><span style=\"font-weight: 400;\">: Recursively searches directories.<\/span>&nbsp;<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">-c<\/span><span style=\"font-weight: 400;\">: Counts the number of matching lines.<\/span>&nbsp;<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">-l<\/span><span style=\"font-weight: 400;\">: Lists filenames containing the match.<\/span>&nbsp;<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">-w<\/span><span style=\"font-weight: 400;\">: Matches whole words only.<\/span>&nbsp;<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">-x<\/span><span style=\"font-weight: 400;\">: Matches whole lines only.<\/span>&nbsp;<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">-E<\/span><span style=\"font-weight: 400;\">: Uses extended regular expressions.<\/span>&nbsp;<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">-F<\/span><span style=\"font-weight: 400;\">: Interprets the pattern as a list of fixed strings.<\/span>&nbsp;<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">-q<\/span><span style=\"font-weight: 400;\">: Suppresses output; useful for scripting.<\/span><\/li>\n<\/ul>\n<p><strong>Read more:\u00a0<a href=\"https:\/\/hostnoc-revamp.branex.org\/blog\/windows-dedicated-server-vs-linux-dedicated-server\/\">Windows Dedicated Server Vs Linux Dedicated Server<\/a><\/strong><\/p>\n<h3><b>Practical Examples<\/b><\/h3>\n<p><b>Basic Search<\/b><span style=\"font-weight: 400;\">: Find lines containing &#8220;<\/span><b>error<\/b><span style=\"font-weight: 400;\">&#8221; in <\/span><span style=\"font-weight: 400;\">app.log<\/span><span style=\"font-weight: 400;\">:<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"> grep &#8220;<\/span><b>error<\/b><span style=\"font-weight: 400;\">&#8221; app.log<\/span><\/p>\n<p><b>Case-Insensitive Search<\/b><span style=\"font-weight: 400;\">: Find lines containing &#8220;<\/span><b>Warning<\/b><span style=\"font-weight: 400;\">&#8221; regardless of case:<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"> grep -i &#8220;<\/span><b>warning<\/b><span style=\"font-weight: 400;\">&#8221; app.log<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><b>Line Numbers<\/b><span style=\"font-weight: 400;\">: Display line numbers where &#8220;<\/span><b>critical<\/b><span style=\"font-weight: 400;\">&#8221; appears:<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"> grep -n &#8220;<\/span><b>critical<\/b><span style=\"font-weight: 400;\">&#8221; app.log<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><b>Recursive Search<\/b><span style=\"font-weight: 400;\">: Search for &#8220;<\/span><b>timeout<\/b><span style=\"font-weight: 400;\">&#8221; in all <\/span><span style=\"font-weight: 400;\">.log<\/span><span style=\"font-weight: 400;\"> files within a directory:<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"> grep -r &#8220;<\/span><b>timeout<\/b><span style=\"font-weight: 400;\">&#8221; *.log<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><b>Count Matches<\/b><span style=\"font-weight: 400;\">: Count occurrences of &#8220;<\/span><b>failed<\/b><span style=\"font-weight: 400;\">&#8221; in <\/span><span style=\"font-weight: 400;\">auth.log<\/span><span style=\"font-weight: 400;\">:<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"> grep -c &#8220;<\/span><b>failed<\/b><span style=\"font-weight: 400;\">&#8221; auth.log<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><b>Exclude Matches<\/b><span style=\"font-weight: 400;\">: Show lines that do not contain &#8220;<\/span><b>debug<\/b><span style=\"font-weight: 400;\">&#8220;:<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"> grep -v &#8220;<\/span><b>debug<\/b><span style=\"font-weight: 400;\">&#8221; app.log<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><b>Contextual Lines<\/b><span style=\"font-weight: 400;\">: Display 2 lines before and after each match for &#8220;<\/span><b>error<\/b><span style=\"font-weight: 400;\">&#8220;:<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"> grep -B 2 -A 2 &#8220;<\/span><b>error<\/b><span style=\"font-weight: 400;\">&#8221; app.log<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><b>Using Regular Expressions<\/b><span style=\"font-weight: 400;\">: Match lines starting with &#8220;start&#8221; or ending with &#8220;end&#8221;:<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"> grep -E &#8220;^start|end$&#8221; file.txt<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><b>Search Compressed Files<\/b><span style=\"font-weight: 400;\">: Search within a gzipped file:<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"> zgrep &#8220;<\/span><b>pattern<\/b><span style=\"font-weight: 400;\">&#8221; file.txt.gz<\/span><\/p>\n<h3><b>Combining with Other Commands<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">grep<\/span><span style=\"font-weight: 400;\"> can be combined with other commands using pipes to filter their output:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">List all processes and filter for &#8220;<\/span><b>nginx<\/b><span style=\"font-weight: 400;\">&#8220;:<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">ps aux | grep &#8220;<\/span><b>nginx<\/b><span style=\"font-weight: 400;\">&#8220;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">:contentReference[oaicite:105]{index=105}<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">&#8211; :contentReference[oaicite:107]{index=107}:contentReference[oaicite:109]{index=109}<\/span><\/p>\n<p><span style=\"font-weight: 400;\">find . -name &#8220;*<\/span><b>.mp3<\/b><span style=\"font-weight: 400;\">&#8221; | grep -i &#8220;JayZ&#8221; | grep -vi &#8220;<\/span><b>remix<\/b><span style=\"font-weight: 400;\">&#8220;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">:contentReference[oaicite:112]{index=112}<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">:contentReference[oaicite:114]{index=114}:contentReference[oaicite:116]{index=116}<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">If you have specific scenarios or need further assistance with `<\/span><b>grep<\/b><span style=\"font-weight: 400;\">`, feel free to ask!<\/span><\/p>\n<p><span style=\"font-weight: 400;\">::contentReference[oaicite:117]{index=117}<\/span><\/p>\n<p style=\"text-align: center;\"><strong><span class=\"highlight\" style=\"background-color:#971a1d;\">One server. One user. One unstoppable experience. That&#8217;s real dedication.<\/span>\n<\/strong><\/p>\n<p style=\"text-align: center;\"><section class=\"dedicated_plans_section plans-section\" id=\"dedicated_plan\">\n    <table id=\"data\" class=\"stackable large-only\">\n        <thead>\n            <tr>\n<!--                 <th class=\"tbl-head-plan\">Plan<\/th> -->\n                <th class=\"tbl-head-cores\">Cores<\/th>\n                <th class=\"tbl-head-ram\">RAM<\/th>\n                <th class=\"tbl-head-storage\">Storage<\/th>\n                <th class=\"tbl-head-plan\">Location<\/th>\n                <th class=\"tbl-head-location\">Monthly Price<\/th>\n                <th class=\"tbl-head-link\">Link<\/th>\n            <\/tr>\n        <\/thead>\n        <tbody>\n        <tr><td colspan=\"6\">No products found.<\/td><\/tr>        <\/tbody>\n    <\/table>\n<\/section>\n    <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Prep Command in Linux Basic Syntax The general syntax for grep is: grep [OPTIONS] PATTERN [FILE&#8230;] This command searches for the specified PATTERN in the given<span class=\"excerpt-hellip\"> [\u2026]<\/span><\/p>\n","protected":false},"author":13,"featured_media":12746,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"content-type":"","footnotes":""},"categories":[203],"tags":[],"class_list":["post-12744","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-guide"],"acf":[],"_links":{"self":[{"href":"https:\/\/hostnoc-revamp.branex.org\/blog\/wp-json\/wp\/v2\/posts\/12744","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hostnoc-revamp.branex.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hostnoc-revamp.branex.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hostnoc-revamp.branex.org\/blog\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/hostnoc-revamp.branex.org\/blog\/wp-json\/wp\/v2\/comments?post=12744"}],"version-history":[{"count":3,"href":"https:\/\/hostnoc-revamp.branex.org\/blog\/wp-json\/wp\/v2\/posts\/12744\/revisions"}],"predecessor-version":[{"id":12749,"href":"https:\/\/hostnoc-revamp.branex.org\/blog\/wp-json\/wp\/v2\/posts\/12744\/revisions\/12749"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/hostnoc-revamp.branex.org\/blog\/wp-json\/wp\/v2\/media\/12746"}],"wp:attachment":[{"href":"https:\/\/hostnoc-revamp.branex.org\/blog\/wp-json\/wp\/v2\/media?parent=12744"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hostnoc-revamp.branex.org\/blog\/wp-json\/wp\/v2\/categories?post=12744"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hostnoc-revamp.branex.org\/blog\/wp-json\/wp\/v2\/tags?post=12744"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}