Linux grep Command आणि Regular Expressions (Regex) Tutorial उदाहरणांसह
grep pattern जुळणाऱ्या lines शोधतो. Regular expression (regex) म्हणजे pattern ची भाषा: 'ERROR ने सुरू होणारी line', 'कोणताही IP address' किंवा '3 ते 5 digits चा word' असं सांगता येतं. Servers debug करताना, code शोधताना किंवा security audit करताना grep आणि regex हे सगळ्यात जास्त वापरलं जाणारं skill.
या chapter मध्ये तुम्ही काय शिकाल
- grep आणि त्याचे मुख्य options ने text शोधा
- Folders recursive शोधा आणि files list करा
- Matches च्या आजूबाजूचा context
- Basic regex: anchors, dot, classes, star
- Extended regex: + ? {n,m} | ( )
- grep -o, -P, fixed strings आणि ripgrep
1. रोजचं उदाहरण: phone book मधे नाव शोधणं
हे का लागतं?
मीराच्या बाबांकडे 2,000 phone numbers असलेली जुनी diary आहे. तिला हवं: 'Joshi' असलेली प्रत्येक line, पण 'Joshi Travels' नाही; 'D' ने सुरू होणारी नावं; 98 ने सुरू होणारे numbers; आणि 'Doctor' खालच्या दोन lines, कारण तिथे clinic ची वेळ लिहिलीय.
हे काय आहे?
Joshi असलेल्या lines = grep Joshi. Travels नाही = grep -v Travels. D ने सुरू = grep '^D'. 98 ने सुरू होणारे numbers = grep -E '\b98[0-9]{8}\b'. खालच्या दोन lines = grep -A2 Doctor.
कसं करायचं (step by step)
2. grep basics: रोज वापरायचे options
हे का लागतं?
Logs आणि configs मोठे असतात. महत्त्वाच्या थोड्याच lines एका second मधे हव्यात.
हे काय आहे?
grep PATTERN FILE जुळणाऱ्या lines print करतो. -i case ignore, -v उलटं (न जुळणाऱ्या), -n line numbers, -c lines मोजा, -w पूर्ण word, -x पूर्ण line, -o फक्त जुळलेला भाग, -m N N matches नंतर थांबा, -q शांत (फक्त exit code), -h/-H file नावं लपवा/दाखवा, --color=auto highlight. Shell ने बदलू नये म्हणून pattern single quotes मधे.
| Option | अर्थ |
|---|---|
| -i | Case ignore |
| -v | न जुळणाऱ्या lines |
| -n | Line numbers |
| -c | जुळणाऱ्या lines मोजा |
| -w | पूर्ण words |
| -o | फक्त जुळलेला text |
| -q | शांत, फक्त exit code |
| -m N | N matches नंतर थांबा |
कसं करायचं (step by step)
- Errors शोधा.
grep ERROR app.log
Output:
10:12:44 ERROR payment timeout order=8812
10:15:02 ERROR db connection refused
याचा अर्थ: फक्त ERROR असलेल्या lines.
- Case ignore आणि line numbers.
grep -in 'timeout' app.log
Output:
57:10:12:44 ERROR payment timeout order=8812
90:10:20:11 WARN Timeout on cache
याचा अर्थ: 57 आणि 90 line numbers.
- Config मधल्या comments आणि रिकाम्या lines लपवा.
grep -v '^#' /etc/ssh/sshd_config | grep -v '^$'
Output:
Port 22
PermitRootLogin no
PasswordAuthentication no
याचा अर्थ: -v उलटं करतो. आता फक्त खरी settings.
- फक्त पूर्ण word.
grep -w 'root' /etc/passwd
Output:
root:x:0:0:root:/root:/bin/bash
याचा अर्थ: -w chroot किंवा rootless skip करतो.
- Failed logins मोजा.
sudo grep -c 'Failed password' /var/log/secure
Output:
143
याचा अर्थ: 143 lines जुळल्या.
- if मधे grep.
if grep -q '^ravi:' /etc/passwd; then echo exists; fi
Output:
exists
याचा अर्थ: -q काही print करत नाही; exit 0 म्हणजे सापडलं.
- अनेक patterns एकदम.
grep -e ERROR -e FATAL app.log | wc -l
Output:
31
याचा अर्थ: -e परत परत देता येतो. किंवा patterns file मधे ठेवून -f.
3. अनेक files आणि folders शोधा
हे का लागतं?
ही setting कुठे आहे? जुना password कोणत्या file मधे? पूर्ण folder tree शोधावं लागतं.
हे काय आहे?
grep -r PATTERN DIR, DIR खालच्या सगळ्या files शोधतो (-R symlinks पण follow). -l फक्त match असलेल्या files ची नावं, -L match नसलेल्या. --include='*.conf' आणि --exclude-dir=.git files filter करतात. -I binary files skip. zgrep .gz files शोधतो.
कसं करायचं (step by step)
- Port कुठे set आहे.
grep -rn 'listen 443' /etc/nginx/
Output:
/etc/nginx/conf.d/shop.conf:5: listen 443 ssl;
याचा अर्थ: File, line number आणि line.
- फक्त file नावं.
grep -rl 'DB_PASSWORD' /srv/app
Output:
/srv/app/.env
/srv/app/config/old.env
याचा अर्थ: Files मधे राहिलेली secrets शोधायला.
- फक्त काही file types.
grep -rn --include='*.py' 'import boto3' ~/projects
Output:
/home/ravi/projects/s3sync/main.py:3:import boto3
याचा अर्थ: .py नसलेलं सगळं skip.
- .git आणि node_modules skip.
grep -rn --exclude-dir={.git,node_modules} 'TODO' .
Output:
./src/cart.js:41: // TODO handle coupon
याचा अर्थ: Fast आणि कमी गोंधळ.
- Rotated gz logs शोधा.
zgrep -c 'Out of memory' /var/log/messages*.gz
Output:
/var/log/messages-1.gz:2
/var/log/messages-2.gz:0
याचा अर्थ: Unzip नको.
- Header नसलेल्या files.
grep -L 'Copyright' src/*.c
Output:
src/new_feature.c
याचा अर्थ: -L match नसलेल्या files.
4. Context: आधीच्या आणि नंतरच्या lines
हे का लागतं?
एकटी error line पूर्ण कथा सांगत नाही. आधीच्या lines कारण, नंतरच्या stack trace दाखवतात.
हे काय आहे?
-A N प्रत्येक match नंतर N lines, -B N आधी, -C N दोन्ही बाजू. Groups -- ने वेगळे. कुठे आहात ते कळायला -n सोबत.
कसं करायचं (step by step)
- Exception नंतरचा stack trace.
grep -A3 'Exception' app.log
Output:
10:20:11 ERROR NullPointerException
at Cart.total(Cart.java:42)
at Checkout.pay(Checkout.java:17)
at Api.post(Api.java:88)
याचा अर्थ: Match नंतर तीन lines.
- Crash आधी काय झालं.
grep -B2 'Killed process' /var/log/messages
Output:
kernel: Out of memory: Killed process 3112 (java)
याचा अर्थ: -B आधीच्या lines.
- Line numbers सह दोन्ही बाजू.
grep -n -C1 'disk full' backup.log
Output:
41-starting upload
42:ERROR disk full
43-retry in 60s
याचा अर्थ: Matches ला :, context lines ला -.
5. Basic regex: anchors, dot, classes आणि star
हे का लागतं?
नुसते words पुरत नाहीत. 'ने सुरू', 'ने संपतं', 'कोणताही digit' किंवा 'इथे कोणताही character' हवं.
हे काय आहे?
^ line ची सुरुवात, $ line चा शेवट, . कोणताही एक character, [abc] a, b, c पैकी एक, [^abc] यापैकी नाही, [0-9] एक digit, [A-Za-z] एक letter, * आधीचा item शून्य किंवा जास्त वेळा, .* काहीही. POSIX classes: [[:digit:]] [[:alpha:]] [[:space:]] [[:upper:]]. \ special character escape करतो: \. म्हणजे खरा dot. GNU grep मधे \b किंवा \< \> word कडा.
| Symbol | अर्थ | उदाहरण |
|---|---|---|
| ^ | Line सुरुवात | ^ERROR |
| $ | Line शेवट | \.conf$ |
| . | कोणताही एक character | h.t |
| [0-9] | एक digit | [0-9][0-9] |
| [^ ] | Space नाही | [^ ]* |
| * | आधीचा 0 किंवा जास्त | ab*c |
| \ | Special char escape | 1\.5 |
| \b | Word कडा | \bcat\b |
कसं करायचं (step by step)
- ERROR ने सुरू होणाऱ्या lines.
grep '^ERROR' worker.log
Output:
ERROR job 77 failed
याचा अर्थ: ^ match सुरुवातीला बांधतो.
- .conf ने संपणाऱ्या lines.
ls /etc | grep '\.conf$' | head -3
Output:
host.conf
ld.so.conf
resolv.conf
याचा अर्थ: \. खरा dot; $ शेवट.
- रिकाम्या lines.
grep -c '^$' notes.txt
Output:
6
याचा अर्थ: ^$ म्हणजे सुरुवात आणि शेवटामधे काही नाही.
- Dot ने कोणताही character.
echo -e 'hat\nhot\nheat' | grep 'h.t'
Output:
hat
hot
याचा अर्थ: h आणि t मधे एक character. 'heat' मधे दोन.
- HTTP 4xx किंवा 5xx codes.
grep ' [45][0-9][0-9] ' access.log | head -2
Output:
10.0.0.7 GET /cart 404 0
10.0.0.2 POST /pay 503 0
याचा अर्थ: Class [45] मग दोन digits.
- एकही digit नसलेल्या lines.
grep -v '[0-9]' list.txt
Output:
apple
banana
याचा अर्थ: -v आणि digit class.
- POSIX class ने uppercase words.
grep -o '\b[[:upper:]][[:upper:]]*\b' notes.txt | sort -u
Output:
AWS
EC2
याचा अर्थ: कोणत्याही language setting मधे चालतं.
6. Extended regex: + ? {n,m} | आणि groups
हे का लागतं?
IPs, emails, phone numbers किंवा 'हे किंवा ते' match करायला repeat counts आणि choices लागतात.
हे काय आहे?
grep -E (किंवा egrep, आता deprecated) extended regex चालू करतो. + एक किंवा जास्त, ? शून्य किंवा एक, {3} नेमके 3, {2,4} 2 ते 4, {2,} 2 किंवा जास्त, a|b यापैकी एक, ( ) groups. Basic grep मधे यालाच backslash: \+ \? \{3\} \| \( \). grep -P Perl regex: \d, \w, \s, lazy .*? आणि lookarounds.
| Symbol (-E) | अर्थ |
|---|---|
| + | 1 किंवा जास्त |
| ? | 0 किंवा 1 (optional) |
| {3} | नेमके 3 |
| {2,4} | 2 ते 4 |
| a|b | a किंवा b |
| ( ) | Group |
कसं करायचं (step by step)
- ERROR किंवा FATAL.
grep -E 'ERROR|FATAL' app.log | wc -l
Output:
31
याचा अर्थ: | म्हणजे किंवा. -E लागतो.
- IPv4 addresses शोधा.
grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}' auth.log | sort -u | head -3
Output:
10.0.0.5
49.36.12.4
103.21.8.77
याचा अर्थ: 1-3 digits आणि dot चा group 3 वेळा, मग 1-3 digits.
- भारतीय mobile numbers.
grep -Eo '\b[6-9][0-9]{9}\b' contacts.txt
Output:
9822012345
7020011122
याचा अर्थ: 6-9 ने सुरू, मग आणखी 9 digits.
- Emails.
grep -Eio '[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}' users.txt
Output:
aditi@example.com
john.doe@mail.co.uk
याचा अर्थ: + म्हणजे एक किंवा जास्त allowed characters.
- Optional letter.
grep -E 'colou?r' notes.txt
Output:
color
colour
याचा अर्थ: u? असू किंवा नसू शकतो.
- Perl regex: order= नंतरची value.
grep -oP 'order=\K\d+' app.log | head -2
Output:
8812
8813
याचा अर्थ: \K आधीचा भाग output मधून काढतो; \d digit.
- तोच pattern basic grep मधे.
grep 'ERROR\|FATAL' app.log | wc -l
Output:
31
याचा अर्थ: Basic regex मधे | ला backslash.
7. Fixed strings, speed आणि ripgrep
हे का लागतं?
Dots किंवा brackets भरलेली string, किंवा लाखो lines शोधायला fast आणि safe मार्ग हवा.
हे काय आहे?
grep -F (fgrep) pattern ला साधा text मानतो: regex नाही, fast आणि escaping नाही. -f file अनेक patterns file मधून. मोठ्या ASCII logs वर LC_ALL=C grep खूप fast. ripgrep (rg) modern recursive grep: fast, .gitignore मानतो, default colour आणि line numbers. ag आणि ack सारखीच tools.
कसं करायचं (step by step)
- Dots असलेली string safely.
grep -F '10.0.0.1' access.log | head -1
Output:
10.0.0.1 GET /p1 200
याचा अर्थ: -F शिवाय . कोणताही character (10x0y0z1).
- File मधून block list.
grep -Ff bad_ips.txt access.log | wc -l
Output:
57
याचा अर्थ: bad_ips.txt ची प्रत्येक line एक pattern.
- मोठ्या log वर speed.
time LC_ALL=C grep -c 'ERROR' big.log
Output:
120334
real 0m0.41s
याचा अर्थ: C locale slow Unicode rules टाळतो.
- Code repo मधे ripgrep.
rg -n 'boto3.client' --type py
Output:
src/sync.py
3:s3 = boto3.client('s3')
याचा अर्थ: rg .gitignore files skip करतो आणि default recursive.
8. अनेक industries मधली खरी उदाहरणं
हे का लागतं?
तेच Linux skill प्रत्येक प्रकारच्या company मध्ये लागतं. वेगवेगळ्या ठिकाणी पाहिलं की लक्षात राहतं.
हे काय आहे?
प्रत्येक row म्हणजे एक काल्पनिक team. कोण हे वापरतं आणि कसं ते दाखवते.
कसं करायचं (step by step)
| Team आणि शहर | ते कसं वापरतात | Command |
|---|---|---|
| Vikram, SOC analyst, Gurugram | SSH logs मधे brute-force IPs | grep 'Failed password' /var/log/secure | grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}' | sort | uniq -c | sort -nr |
| Hannah, fintech, Zurich | Logs मधे card numbers नाहीत ना | grep -rEn '\b[0-9]{16}\b' /var/log/app |
| Omar, airline ops, Doha | Booking failures चा context | grep -C3 'PNR_FAIL' booking.log |
| Kavya, QA, Pune | Code मधे TODO राहिलं तर CI fail | ! grep -rn 'TODO' src/ |
| Mateo, e-commerce, Buenos Aires | दर मिनिटाचे 5xx errors | grep -E '" 5[0-9]{2} ' access.log | cut -c14-30 | uniq -c |
| Yuki, platform, Osaka | कोणता config timeout set करतो | grep -rn --include='*.yaml' 'timeout:' k8s/ |
9. नेहमीच्या errors आणि त्यांचे fixes
हे का लागतं?
हे errors सगळ्यांना येतात. कारण माहीत असलं की तास वाचतात.
हे काय आहे?
आधी नेमका message वाचा. मग खालच्या row शी जुळवा.
कसं करायचं (step by step)
| दिसणारा error | का होतं | Fix कसा करायचा |
|---|---|---|
grep: app.log: No such file or directory | चुकीचा file path | ls ने path तपासा.ls /var/log/app/ |
grep: /var/log/secure: Permission denied | File फक्त root ला | sudo वापरा.sudo grep sshd /var/log/secure |
grep: Unmatched ( or \( | Pattern मधला bracket बंद नाही किंवा escape नाही | Escape करा किंवा साध्या text साठी -F.grep -F 'f(x)' code.c |
grep: Invalid range end | [z-a] सारखी range किंवा locale | Range कमी ते जास्त किंवा classes.grep '[[:alpha:]]' f |
Binary file app.bin matches | Binary file मधे match | Text मानायला -a, binaries skip ला -I.grep -a 'version' app.bin |
Pattern with | matches nothing | | ला -E लागतो (basic मधे \|) | -E जोडा.grep -E 'a|b' f |
grep -r is very slow | .git, node_modules किंवा मोठ्या binaries शोधतोय | Folders exclude करा किंवा rg.grep -r --exclude-dir=node_modules x . |
grep: warning: egrep is obsolescent | egrep आणि fgrep deprecated | grep -E आणि grep -F.grep -E 'x|y' f |
Pattern with $ matches wrong | Double quotes मुळे shell $VAR expand करतो | Single quotes वापरा.grep 'price$' f |
grep -P: unsupported on this system | BusyBox किंवा macOS grep मधे -P नाही | -E वापरा, किंवा GNU grep / ripgrep install.grep -Eo 'order=[0-9]+' f |
10. Troubleshooting step by step
हे का लागतं?
grep ला काहीच सापडलं नाही (किंवा खूप सापडलं) तर आधी छोट्या sample वर pattern test करा.
हे काय आहे?
वरून खाली जा. ज्या step ला problem दिसतो तिथे थांबा.
कसं करायचं (step by step)
- Text खरंच आहे का? आधी साधा -F.
grep -F -c 'timeout' app.log
- Case problem? -i जोडा.
grep -ic 'timeout' app.log
- एका echo line वर regex test.
echo 'order=8812 ok' | grep -Eo 'order=[0-9]+'
- File मधे hidden characters (\r, tabs)?
grep -m1 'timeout' app.log | cat -A
- Binary किंवा compressed?
file app.log
- Exit code तपासा.
grep -q x app.log; echo $?
11. Lab 1: SSH brute-force attack शोधा
हे का लागतं?
grep आणि regex ने कोण attack करतंय, किती वेळा आणि कोणते users try करतंय ते शोधा.
हे काय आहे?
पूर्ण hands-on lab. प्रत्येक step test Linux machine वर करा (EC2 instance, VM किंवा WSL).
कसं करायचं (step by step)
- Sample auth log बनवा.
mkdir -p ~/lab9 && cd ~/lab9 && for i in $(seq 1 60); do echo "Oct 25 10:$((i%60)):01 web sshd[9$i]: Failed password for $([ $((i%3)) = 0 ] && echo invalid user admin || echo root) from 49.36.12.$((i%4)) port 5$i ssh2"; done > auth.log; echo 'Oct 25 11:00:00 web sshd[1]: Accepted publickey for ravi from 10.0.0.5' >> auth.log
Output:
(no output)
- Failures मोजा.
grep -c 'Failed password' auth.log
Output:
60
- Attacking IPs काढा आणि मोजा.
grep 'Failed' auth.log | grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}' | sort | uniq -c | sort -nr
Output:
15 49.36.12.0
15 49.36.12.1
15 49.36.12.2
15 49.36.12.3
- कोणते users try केले?
grep -oP 'for (invalid user )?\K\w+' auth.log | sort | uniq -c
Output:
20 admin
40 root
1 ravi
- चांगला login context सह.
grep -B1 'Accepted' auth.log
Output:
Oct 25 10:0:01 web sshd[960]: Failed password for invalid user admin ...
Oct 25 11:00:00 web sshd[1]: Accepted publickey for ravi from 10.0.0.5
12. Lab 2: Code folder मधे secrets audit
हे का लागतं?
Include आणि exclude rules सह recursive search करा आणि risky files list करा.
हे काय आहे?
पूर्ण hands-on lab. प्रत्येक step test Linux machine वर करा (EC2 instance, VM किंवा WSL).
कसं करायचं (step by step)
- छोटा project बनवा.
cd ~/lab9 && mkdir -p proj/src proj/.git && echo 'AWS_SECRET=abc123' > proj/src/.env && echo 'print(1)' > proj/src/a.py && echo 'AWS_SECRET=old' > proj/.git/x
Output:
(no output)
- सगळं शोधा.
grep -rn 'AWS_SECRET' proj
Output:
proj/src/.env:1:AWS_SECRET=abc123
proj/.git/x:1:AWS_SECRET=old
- .git skip करून फक्त file नावं.
grep -rl --exclude-dir=.git 'AWS_SECRET' proj
Output:
proj/src/.env
- AWS access key id patterns.
echo 'key=AKIAIOSFODNN7EXAMPLE' >> proj/src/a.py; grep -rEon 'AKIA[0-9A-Z]{16}' proj/src
Output:
proj/src/a.py:2:AKIAIOSFODNN7EXAMPLE
Ravindra Bagale's Tip
Always put grep patterns in single quotes, and test a new regex with echo on one sample line before running it on a 5 GB log. It saves time and avoids shell surprises.
Ravindra Bagale's Tip – मराठी
grep patterns नेहमी single quotes मधे ठेवा, आणि नवा regex 5 GB log वर चालवायच्या आधी echo ने एका sample line वर test करा. वेळ वाचतो आणि shell चे surprises टळतात.
Ravindra Bagale's Tip – हिंदी
grep patterns हमेशा single quotes में रखें, और नया regex 5 GB log पर चलाने से पहले echo से एक sample line पर test करें. समय बचता है और shell के surprises टलते हैं.
13. नेहमी विचारले जाणारे प्रश्न
प्र. grep, grep -E आणि grep -F मधे फरक?
grep basic regex, -E extended regex (backslash शिवाय + ? | {}), -F regex नसलेला साधा text.
प्र. grep . सगळं का match करतो?
Dot म्हणजे कोणताही character. खऱ्या dot साठी \. किंवा -F.
प्र. Dash ने सुरू होणारा word कसा शोधायचा?
-e किंवा --: grep -e '-v' file.
प्र. grep lines पलीकडे शोधतो का?
नाही, line by line. Multi-line साठी grep -z किंवा (?s) सह -P, किंवा awk/sed.
प्र. grep चा exit code?
0 match सापडला, 1 नाही, 2 error.
प्र. Regex आणि shell globs एकच का?
नाही. Globs मधे * म्हणजे काहीही; regex मधे * म्हणजे 'आधीचा item repeat'. Regex मधे काहीही म्हणजे .*.
प्र. ripgrep वापरावा का?
Laptop वर code search साठी हो. Servers वर grep नेहमी असतो, म्हणून आधी grep.
प्र. फक्त जुळलेला text कसा दाखवायचा?
grep -o.
14. मुलाखत प्रश्न आणि उत्तरं
Beginner level
प्र. Case ignore करून word कसा शोधाल?
grep -i word file.
प्र. न जुळणाऱ्या lines कशा दाखवाल?
grep -v pattern file.
प्र. Folder मधल्या सगळ्या files कशा शोधाल?
grep -r pattern folder/ (line numbers साठी -n).
प्र. ^ आणि $ म्हणजे?
Line ची सुरुवात आणि शेवट.
Mid level level
प्र. प्रत्येक match नंतर 5 lines.
grep -A5 pattern file.
प्र. Log मधून सगळे IP addresses काढा.
grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}' file.
प्र. String असलेल्या files च list करा.
grep -rl string dir.
प्र. Comments आणि blanks शिवाय config lines.
grep -Ev '^\s*(#|$)' file.
Senior level
प्र. 30 GB log वर grep slow. Speed कसा वाढवाल?
LC_ALL=C, fixed strings साठी -F, pattern anchor करा, लवकर थांबायला -m, फक्त time window शोधा (sed/awk ranges), rotated files वर parallel, किंवा ripgrep.
प्र. Basic vs extended vs PCRE regex?
BRE ला + ? | {} () आधी \ लागतो. ERE (-E) ला नाही. PCRE (-P) मधे \d \w, lazy quantifiers, lookahead/behind आणि \K.
प्र. Secrets जोडणारा merge CI मधे कसा थांबवाल?
Pre-commit किंवा CI step: git diff --cached | grep -E 'AKIA[0-9A-Z]{16}|BEGIN RSA PRIVATE' आणि exit 0 ला fail; अजून चांगलं, gitleaks किंवा trufflehog.
प्र. grep -c आणि grep -o | wc -l वेगळे numbers का देतात?
-c match असलेल्या lines मोजतो; -o प्रत्येक match print करतो, म्हणून 3 matches असलेली line 3 मोजली जाते.
घरी करून बघा
- तुमच्या 10 contacts (नाव आणि phone) ची file बनवा. 9 ने सुरू होणारे numbers grep -E ने आणि 'a' असलेली नावं grep -c ने मोजा.
- कोणत्याही Linux box वर 'grep -v ^# /etc/ssh/sshd_config | grep -v ^$' चालवा आणि दिसणारी खरी settings लिहा.
सराव Tasks
London Legal LLP हा लंडन मधला कायदा सेवा व्यवसाय आहे. Oliver Hughes त्यांचं IT व cloud काम पाहतात. त्यांचे पैसे GBP मध्ये मोजले जातात आणि AWS resources eu-west-2 Region मध्ये चालतात. खालच्या tasks मध्ये तुम्ही या lesson मध्ये शिकलेलं वापरून त्यांची खरी कामं करता. सगळी नावं, account IDs, IP addresses व numbers सरावासाठी काल्पनिक आहेत.
0 / 16
सोपं Case ignore करून search
का: Error, ERROR, error सगळे महत्त्वाचे.
काय करायचं: app.log मधे कोणत्याही case मधे error शब्द असलेल्या lines.
- हे काम करणारा Linux command शोधा.
- Task ला लागणारे options (उदा. -r, -h) जोडा.
- File नावं, folders किंवा users योग्य क्रमाने लिहा.
- System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.
सोपं Line numbers दाखवा
का: vim मधे योग्य line वर जा.
काय करायचं: app.log मधे timeout शोधा आणि line numbers दाखवा.
- हे काम करणारा Linux command शोधा.
- Task ला लागणारे options (उदा. -r, -h) जोडा.
- File नावं, folders किंवा users योग्य क्रमाने लिहा.
- System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.
सोपं Comment lines लपवा
का: फक्त active settings.
काय करायचं: sshd_config च्या # ने सुरू न होणाऱ्या lines. Pattern '^#'.
- हे काम करणारा Linux command शोधा.
- Task ला लागणारे options (उदा. -r, -h) जोडा.
- File नावं, folders किंवा users योग्य क्रमाने लिहा.
- System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.
सोपं जुळणाऱ्या lines मोजा
का: किती 500 errors?
काय करायचं: फक्त grep ने access.log मधे " 500 " असलेल्या lines मोजा. Pattern ' 500 '.
- हे काम करणारा Linux command शोधा.
- Task ला लागणारे options (उदा. -r, -h) जोडा.
- File नावं, folders किंवा users योग्य क्रमाने लिहा.
- System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.
सोपं Regex end anchor
का: Line च्या शेवटी match.
काय करायचं: कोणता एक regex character line चा शेवट?
- Task मधले numbers लिहून घ्या.
- कागदावर step by step काढा.
- Box मध्ये फक्त final उत्तर लिहा.
- Check answer दाबा.
मध्यम पूर्ण project मधे search
का: DB password कुठे वापरला?
काय करायचं: src folder मधे recursively DB_PASS शोधा, line numbers सह.
- हे काम करणारा Linux command शोधा.
- Task ला लागणारे options (उदा. -r, -h) जोडा.
- File नावं, folders किंवा users योग्य क्रमाने लिहा.
- System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.
मध्यम फक्त file नावं
का: कोणत्या files edit करायच्या एवढंच.
काय करायचं: conf खालच्या listen असलेल्या files ची फक्त नावं, recursively.
- हे काम करणारा Linux command शोधा.
- Task ला लागणारे options (उदा. -r, -h) जोडा.
- File नावं, folders किंवा users योग्य क्रमाने लिहा.
- System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.
मध्यम फक्त पूर्ण शब्द
का: cat ने category जुळू नये.
काय करायचं: pets.txt मधे पूर्ण शब्द cat असलेल्या lines.
- हे काम करणारा Linux command शोधा.
- Task ला लागणारे options (उदा. -r, -h) जोडा.
- File नावं, folders किंवा users योग्य क्रमाने लिहा.
- System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.
मध्यम Match नंतरच्या lines
का: Error line नंतर stack trace.
काय करायचं: app.log मधली प्रत्येक Exception line आणि नंतरच्या 5 lines.
- हे काम करणारा Linux command शोधा.
- Task ला लागणारे options (उदा. -r, -h) जोडा.
- File नावं, folders किंवा users योग्य क्रमाने लिहा.
- System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.
मध्यम Match च्या आजूबाजूला
का: Crash च्या आजूबाजूला काय झालं.
काय करायचं: kern.log मधल्या प्रत्येक OOM line च्या आधी आणि नंतर 3 lines.
- हे काम करणारा Linux command शोधा.
- Task ला लागणारे options (उदा. -r, -h) जोडा.
- File नावं, folders किंवा users योग्य क्रमाने लिहा.
- System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.
मध्यम शब्दाने सुरू होणाऱ्या lines
का: फक्त खरे directives.
काय करायचं: nginx.conf मधल्या server ने सुरू होणाऱ्या lines. Quotes मधे anchor.
- हे काम करणारा Linux command शोधा.
- Task ला लागणारे options (उदा. -r, -h) जोडा.
- File नावं, folders किंवा users योग्य क्रमाने लिहा.
- System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.
मध्यम Literal string search
का: इथे dots आणि stars regex नाहीत.
काय करायचं: rules.txt मधे 1.2.3.* हा exact text fixed string म्हणून शोधा. Quote करा.
- हे काम करणारा Linux command शोधा.
- Task ला लागणारे options (उदा. -r, -h) जोडा.
- File नावं, folders किंवा users योग्य क्रमाने लिहा.
- System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.
मध्यम Process शोधा
का: nginx चालू आहे का?
काय करायचं: ps aux ने सगळे processes आणि nginx lines filter.
- हे काम करणारा Linux command शोधा.
- Task ला लागणारे options (उदा. -r, -h) जोडा.
- File नावं, folders किंवा users योग्य क्रमाने लिहा.
- System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.
अवघड दोन शब्द जुळवा
का: दोन्ही प्रकारचे failures.
काय करायचं: Extended regex ने api.log मधे WARN किंवा CRIT lines. Pattern 'WARN|CRIT'.
- हे काम करणारा Linux command शोधा.
- Task ला लागणारे options (उदा. -r, -h) जोडा.
- File नावं, folders किंवा users योग्य क्रमाने लिहा.
- System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.
अवघड फक्त IPs काढा
का: Client IPs ची list.
काय करायचं: -oE आणि pattern '[0-9]+(\.[0-9]+){3}' ने access.log मधून फक्त IPv4 भाग.
- हे काम करणारा Linux command शोधा.
- Task ला लागणारे options (उदा. -r, -h) जोडा.
- File नावं, folders किंवा users योग्य क्रमाने लिहा.
- System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.
अवघड फक्त काही file types
का: node_modules गोंधळ टाळा.
काय करायचं: Current folder (.) मधे recursively TODO शोधा, पण फक्त *.py files मधे. --include='*.py'.
- हे काम करणारा Linux command शोधा.
- Task ला लागणारे options (उदा. -r, -h) जोडा.
- File नावं, folders किंवा users योग्य क्रमाने लिहा.
- System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.
15. संबंधित chapters
- DevOps साठी Linux Ops Refresh
- Automation साठी Bash Scripting
- Linux grep आणि find Commands Examples सह
- Linux Servers मध्ये Passwordless SSH
थोडक्यात सांगायचं तर
- grep -i -v -n -c -w -o -q रोजचे options.
- grep -rn folders; -l files list; --include, --exclude-dir filter.
- -A -B -C context.
- Basic regex: ^ $ . [ ] * \.
- grep -E: + ? {n,m} | ( ); -P: \d \K lookarounds.
- साध्या text साठी -F; fast code search साठी rg.
उजळणी, तुलना आणि मुलाखत cards
हा lesson काही मिनिटांत revise करा. Cards phone वर save करा किंवा PNG download करा. प्रत्येक card वरचा QR हा lesson उघडतो.








अजून cards: Ravi Sir's Cards.