Learn Linux Like Pro | grep Command | Basic Linux Command
#LINUX BASIC COMMAND | #LINUX_EXPERTISE | LINUX COMMAND
Learn Linux Like Pro | Linux Basics ls Commands | Linux Commands
Linux Basic Commands | Linux Command
Linux is a computer operating system free for development and distribution, both commercially and non-commercially. There are times when you may spend hours doing a repetitive task. A person who knows command line can write a script in 10 minutes and if he has to repeat it, can do it in a second. So what is Command Line and why is it so popular? Command line applications provide us with numerous benefits which cannot be achieved with any of the available GUI applications. One can create scripts to automate work, and can go so much deeper into the system and explore things that would generally be not possible with GUI.
Linux bash shell programming tutorials. Learn the Linux/ Unix command line (Bash) with beginners tutorial. Clear descriptions, command outlines, examples, shortcuts and best practice. Learn the Command Line. Linux Terminal Tutorial. Linux Command Line Basics. Searches related to Linux command line tutorial for beginners. Linux command line tutorial .learn Linux command line. Linux command line basics. Linux command line prompt. Linux command line cheat sheet. Linux command with example
basic Linux command. Linux tutorial for beginners.
Here are some basic Linux commands along with their short descriptions :
The 'grep' command is a powerful tool used in Unix-based operating systems (like Linux) and in the macOS terminal. It stands for "Global Regular Expression Print." The primary purpose of 'grep' is to search for specific patterns within files or input streams and print the lines that match those patterns.
Here's a detailed breakdown of the 'grep' command and its various options:
Basic Syntax:
grep [options] pattern [file...]
'pattern': The regular expression pattern you want to search for.
'[file...]': Optional argument. If provided, 'grep' searches for the pattern in the specified files. If not provided, 'grep' reads from the standard input (e.g., output of another command via a pipe).
Common Options:
1. -i, --ignore-case : Ignore case distinctions in both the pattern and input files.
2. -v, --invert-match : Invert the sense of matching, i.e., display non-matching lines.
3. -n, --line-number : Prefix each line of output with the line number within its input file.
4. -r, --recursive : Recursively search subdirectories listed.
5. -E, --extended-regexp : Interpret the pattern as an extended regular expression (ERE).
6. -w, --word-regexp : Select only those lines containing matches that form whole words.
7. -A NUM, --after-context=NUM : Print NUM lines of trailing context after matching lines.
8. -B NUM, --before-context=NUM : Print NUM lines of leading context before matching lines.
9. -C NUM, --context=NUM : Print NUM lines of output context.
Examples:
1. Search for a word in a file:
grep "word" filename.txt
2. Case-insensitive search:
grep -i "pattern" filename.txt
3. Search recursively in directories:
grep -r "pattern" directory/
4. Display line numbers along with matching lines:
grep -n "pattern" filename.txt
5. Invert match (show lines that don't match):
grep -v "pattern" filename.txt
6. Search for whole words only:
grep -w "word" filename.txt
7. Display lines before and after the match:
grep -C 2 "pattern" filename.txt
These are just a few common examples of using 'grep'. The command offers a wide range of options for customizing searches based on regular expressions, making it a versatile tool for text processing and manipulation in Unix-like systems.