Skip to Content

Reading Files

Server-এ কোনো GUI নেই — শুধু terminal। তাই terminal থেকে files পড়তে পারাটা একটা core skill। Log files দেখা, config চেক করা, output analyze করা — সব এখান থেকে।

The Tools at a Glance

Commandকাজকখন use করবে
catপুরো file একসাথে print করেছোট files
lessScroll করে পড়া যায়বড় files
headFile-এর শুরু দেখায়প্রথম কয়েক লাইন দরকার
tailFile-এর শেষ দেখায়Latest log entries
tail -fLive update দেখায়Real-time monitoring

cat

পুরো file-এর content একবারে print করে।

Terminal
# File পড়ো cat notes.txt # Line numbers সহ cat -n notes.txt # একাধিক files একসাথে দেখো cat file1.txt file2.txt # System files দেখার common use cat /etc/hostname cat /etc/passwd

cat ছোট files-এর জন্য perfect। বড় file হলে সব output একসাথে scroll হয়ে চলে যায় — তখন less use করো।

less

File navigate করা যায় — উপরে নিচে scroll করো।

Terminal
less /var/log/syslog

less এর ভেতরে keyboard controls:

Keyকাজ
Spaceএক page নিচে
bএক page উপরে
/ এক line নিচে / উপরে
gFile-এর শুরুতে যাও
GFile-এর শেষে যাও
/patternনিচের দিকে search করো
?patternউপরের দিকে search করো
nপরের search result
qExit করো

less সবচেয়ে comfortable reading tool। বড় log files দেখার সময় সবসময় less use করো — cat দিলে terminal flood হয়।

File-এর শুরু থেকে কয়েকটা line দেখায়। Default: ১০ লাইন।

Terminal
# প্রথম ১০ লাইন (default) head /etc/passwd # প্রথম ৫ লাইন head -n 5 notes.txt # প্রথম ২০ লাইন head -20 /var/log/syslog

tail

File-এর শেষ থেকে কয়েকটা line দেখায়। Default: ১০ লাইন।

Terminal
# শেষ ১০ লাইন (default) tail /var/log/syslog # শেষ ২০ লাইন tail -n 20 /var/log/auth.log # শেষ ৫০ লাইন tail -50 /var/log/apache2/access.log

tail -f

File-এ নতুন content আসলে real-time দেখায়। Log monitoring-এ irreplaceable।

Terminal
# Live log monitor করো tail -f /var/log/syslog # Authentication log live দেখো (login attempts) tail -f /var/log/auth.log # Apache access log live tail -f /var/log/apache2/access.log

বন্ধ করতে Ctrl + C চাপো।

CyberSec use: কেউ server-এ login করার চেষ্টা করছে কিনা real-time দেখতে:

Terminal
tail -f /var/log/auth.log

Successful আর failed login দুটোই এখানে আসে।

Combining Tools

Tools combine করে আরো powerful হয়:

Terminal
# Log-এর শেষ ১০০ লাইন less-এ দেখো tail -100 /var/log/syslog | less # File-এ কতটা লাইন আছে cat /etc/passwd | wc -l # প্রথম ৫ লাইন, তারপর শেষ ২ লাইন head -5 notes.txt tail -2 notes.txt

CyberSec Note

Log analysis — the core of incident response:

সব attack-এর trace থাকে log-এ। এই commands দিয়ে:

Terminal
# কে কখন login করেছে tail -50 /var/log/auth.log # Web server-এ কোন IP বেশি request করছে tail -f /var/log/apache2/access.log # System-এ কী হচ্ছে real-time tail -f /var/log/syslog # Sudo commands কে চালিয়েছে grep "sudo" /var/log/auth.log | tail -20

CTF-এ প্রায়ই একটা log file দেওয়া হয় এবং সেখান থেকে attacker-এর activity বের করতে হয়।

Quick Check

  • cat আর less — কখন কোনটা use করবে?
  • head -20 মানে কী?
  • Real-time log monitor করার command কী?
  • tail -f থেকে বের হওয়ার shortcut কী?

পরবর্তী → Searching

Search Keywords: linux cat less head tail, read file terminal, tail -f live log, linux log analysis, reading files linux bangla

Last updated on