1. grep (Global Regular Expression Print):
Used to search text or patterns inside files.
Syntax:
grep [options] "pattern" filename
Common options:
-i→ ignore case-n→ show line numbers-r→ search recursively in directories-v→ invert match (show lines that don’t match)-c→ count matching lines
Examples:
grep "hello" file.txt # Find lines containing "hello"
grep -i "hello" file.txt # Case-insensitive search
grep -n "main" program.c # Show line numbers with matches
grep -r "error" /var/log/ # Search for "error" in all files recursively
grep -v "test" file.txt # Show all lines except those with "test"
2. find
Used to search for files and directories in a directory hierarchy.
Syntax:
find [path] [options] [expression]
Common options:
-name→ search by filename-iname→ case-insensitive name search-type→ search by type (ffor file,dfor directory)-size→ search by size-mtime→ search by modification time
Examples:
find /home -name "*.txt" # Find all .txt files in /home
find . -iname "file.txt" # Find file.txt (ignore case) in current dir
find / -type d -name "logs" # Find directories named "logs"
find . -type f -size +10M # Find files larger than 10 MB
find . -mtime -2 # Find files modified in the last 2 days
3. wc (Word Count)
Used to count lines, words, and characters in a file.
Syntax:
wc [options] filename
Common options:
-l→ count lines-w→ count words-c→ count bytes (characters)-m→ count characters (multi-byte safe)
Examples:
wc file.txt # Show lines, words, characters
wc -l file.txt # Count only lines
wc -w file.txt # Count only words
wc -c file.txt # Count only bytes
wc -m file.txt # Count only characters
cat file.txt | wc -l # Count lines using pipe
Quick summary:
grep→ Search inside file contentsfind→ Search for files/directorieswc→ Count lines, words, characters
Categories:
Laksh
Good , keep going