Searching
Thousands of files-এর মধ্যে একটা specific file খোঁজা, বা একটা file-এ specific text খোঁজা — এই দুটো কাজ terminal থেকে seconds-এ হয়। Cybersecurity-তে এই skills ছাড়া কাজ করা প্রায় impossible।
Two Types of Search
| Tool | কী খোঁজে |
|---|---|
grep | File-এর ভেতরে text pattern খোঁজে |
find | Filesystem-এ files আর folders খোঁজে |
grep
File-এর ভেতরে text pattern খোঁজে এবং matching lines দেখায়।
Terminal
# Basic — file-এ "error" word খোঁজো
grep "error" logfile.txt
# Case-insensitive — Error, ERROR, error সব match করবে
grep -i "error" logfile.txt
# Line numbers সহ দেখাও
grep -n "failed" auth.log
# Invert — "error" নেই এমন lines দেখাও
grep -v "error" logfile.txt
# Recursive — folder-এর সব files-এ খোঁজো
grep -r "password" /etc/
# শুধু matching filename দেখাও (content না)
grep -l "root" /etc/*
# Match-এর আগে-পরে context দেখাও
grep -A 2 "Failed password" auth.log # পরের ২ লাইন
grep -B 2 "Failed password" auth.log # আগের ২ লাইন
grep -C 2 "Failed password" auth.log # দুইদিকে ২ লাইনUseful Patterns
Terminal
# IP address pattern খোঁজো
grep -E "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}" access.log
# "password" বা "passwd" যেকোনোটা
grep -E "password|passwd" config.txt
# Line শুরুতে "root" আছে
grep "^root" /etc/passwd
# Line শেষে "/bin/bash" আছে
grep "/bin/bash$" /etc/passwdfind
Filesystem-এ files, folders খোঁজে — নাম, type, permission, size, date দিয়ে filter করা যায়।
Terminal
# নাম দিয়ে খোঁজো
find / -name "passwords.txt"
# Case-insensitive নাম
find / -iname "readme.md"
# Current folder থেকে খোঁজো
find . -name "*.txt"
# শুধু files খোঁজো (directories না)
find /home -type f
# শুধু directories খোঁজো
find /home -type d
# নির্দিষ্ট extension
find /var/log -name "*.log"Finding by Permission
Terminal
# SUID bit আছে এমন files
find / -perm -4000 2>/dev/null
# World-writable files (সবাই write করতে পারে)
find / -perm -o+w 2>/dev/null
# Specific permission
find / -perm 777 2>/dev/nullFinding by Time
Terminal
# শেষ ১ দিনে modified
find /var/log -mtime -1
# ঠিক ৭ দিন আগে modified
find / -mtime 7
# শেষ ১ ঘণ্টায় modified
find / -mmin -60Finding by Owner
Terminal
# root-owned files
find / -user root -type f 2>/dev/null
# omar-এর files
find /home -user omar2>/dev/null মানে error messages (permission denied etc.) লুকাও। Search করার সময় এটা add করলে output অনেক clean হয়।
Combining grep and find
Terminal
# খোঁজো log files-এ "FAILED" আছে কিনা
find /var/log -name "*.log" | xargs grep "FAILED"
# সব config files-এ "password" search করো
find /etc -type f | xargs grep -l "password" 2>/dev/nullCyberSec Note
এই commands CTF আর pentesting-এ সবচেয়ে বেশি use হয়:
Terminal
# Juicy files খোঁজো
find / -name "*.txt" 2>/dev/null
find / -name "flag*" 2>/dev/null
find / -name "*.conf" 2>/dev/null
# Hardcoded passwords খোঁজো
grep -r "password" /var/www/ 2>/dev/null
grep -r "passwd" /etc/ 2>/dev/null
grep -ri "api_key" /home/ 2>/dev/null
# Privilege escalation — SUID executables
find / -perm -4000 -type f 2>/dev/null
# SSH keys খোঁজো
find / -name "id_rsa" 2>/dev/null
# Writable folders (script drop করা যাবে)
find / -writable -type d 2>/dev/nullTryHackMe-এর প্রায় প্রতিটা Linux challenge-এ এই commands লাগে।
Quick Check
-
grep -rআরgrepএর পার্থক্য কী? -
grep -iকী করে? -
find / -perm -4000কী খোঁজে? -
2>/dev/nullকেন use করা হয়?
পরবর্তী → Text Editors
Last updated on