Prep Command in Linux: All You Need To Know
Prep Command in Linux
Basic Syntax
The general syntax for grep is:
grep [OPTIONS] PATTERN [FILE…]
This command searches for the specified PATTERN in the given FILE or from standard input.
Commonly Used Options
- -i: Performs a case-insensitive search.
- -v: Inverts the match to select non-matching lines.
- -n: Displays line numbers along with matching lines.
- -r or -R: Recursively searches directories.
- -c: Counts the number of matching lines.
- -l: Lists filenames containing the match.
- -w: Matches whole words only.
- -x: Matches whole lines only.
- -E: Uses extended regular expressions.
- -F: Interprets the pattern as a list of fixed strings.
- -q: Suppresses output; useful for scripting.
Read more: Windows Dedicated Server Vs Linux Dedicated Server
Practical Examples
Basic Search: Find lines containing “error” in app.log:
grep “error” app.log
Case-Insensitive Search: Find lines containing “Warning” regardless of case:
grep -i “warning” app.log
Line Numbers: Display line numbers where “critical” appears:
grep -n “critical” app.log
Recursive Search: Search for “timeout” in all .log files within a directory:
grep -r “timeout” *.log
Count Matches: Count occurrences of “failed” in auth.log:
grep -c “failed” auth.log
Exclude Matches: Show lines that do not contain “debug“:
grep -v “debug” app.log
Contextual Lines: Display 2 lines before and after each match for “error“:
grep -B 2 -A 2 “error” app.log
Using Regular Expressions: Match lines starting with “start” or ending with “end”:
grep -E “^start|end$” file.txt
Search Compressed Files: Search within a gzipped file:
zgrep “pattern” file.txt.gz
Combining with Other Commands
grep can be combined with other commands using pipes to filter their output:
- List all processes and filter for “nginx“:
ps aux | grep “nginx“
:contentReference[oaicite:105]{index=105}
– :contentReference[oaicite:107]{index=107}:contentReference[oaicite:109]{index=109}
find . -name “*.mp3” | grep -i “JayZ” | grep -vi “remix“
:contentReference[oaicite:112]{index=112}
:contentReference[oaicite:114]{index=114}:contentReference[oaicite:116]{index=116}
If you have specific scenarios or need further assistance with `grep`, feel free to ask!
::contentReference[oaicite:117]{index=117}
One server. One user. One unstoppable experience. That’s real dedication.
Cores
RAM
Storage
Location
Monthly Price
Link
No products found.
Muhammad Osama
Featured Post
n8n Docker Installation Guide: Complete Step-by-Step Setup for Beginners and Production
Step-by-step n8n Docker installation guide covering Docker Compose, PostgreSQL, HTTPS, environment variables,...
15 n8n Workflow Examples to Automate Your Business
Real n8n workflow examples for marketing, sales, support, AI and DevOps, with...
n8n Workflows for Businesses: A Comprehensive Guide
A complete guide to n8n workflows for businesses: how they work, core...








