Ravindra BagaleCourses & study guides मराठी Track your progress

5. Linux Basic Commands

5.4 Viewing Files and Following Logs

Command Use
cat file Print entire file
less file Scroll page by page (Space next, b back, /word search, q quit)
more file Older, simpler pager
head -n 20 file First 20 lines
tail -n 20 file Last 20 lines
tail -​f /​var/​log/​nginx/​access.​log Follow a log live (Ctrl+C to stop)
wc -l file Count lines (-w words, -c bytes)
diff a b Show differences between two files
cat /etc/os-release          # which Linux distribution and version?
head -5 /etc/passwd
sudo tail -f /var/log/messages      # Amazon Linux / CentOS system log
sudo tail -f /var/log/syslog        # Ubuntu system log

Why this matters for security

tail -f on an auth or web log is the simplest real-time monitoring there is. While you practise brute force in Part 10, keep sudo tail -f /var/log/auth.log (Ubuntu) or sudo journalctl -u sshd -f (Amazon Linux 2023) open on the target – you will see the attack exactly as a SOC analyst sees it.

Ravindra Bagale's Tip

When you cat a large log file, the screen fills up and many students panic. Always open a large file with less or tail -n 50. Use cat only for small files.

Practice task

Show the first 5 and last 5 lines of /etc/passwd, count its lines with wc -l, and follow the system log live for one minute.

Extended teaching notes

Why this lesson matters

A SOC turns logs into action. Good juniors triage with playbooks: what fired, which asset, how bad, contain or escalate, write the timeline.

  1. Prepare: asset list, contacts, runbooks.
  2. Detect: SIEM/EDR alerts with context.
  3. Contain: disable account, isolate host, block IOC.
  4. Eradicate & recover: patch, rebuild, restore.
  5. Lessons: one improvement ticket per incident.

Indian company (sample)

A 24×7 SOC at a large Indian IT services firm handles phishing and malware for many clients. Tier-1 analysts follow a script; they do not freestyle on production.

Mini case study

Suppose we are on a purple-team exercise for an Indian mid-size company (sample data). Red notes a technique from this lesson against a lab clone. Blue must show the control that stops it, the log that would have fired, and the ticket that hardens production. That is the standard this course trains you for.

Defender's worksheet (do this today)

  1. Write the lesson title, date and the exact lab target you are allowed to use.
  2. List three owned systems (VMs, apps, or cloud accounts) where this lesson applies.
  3. Run one safe check from the lesson on a lab system only. Paste the command and output.
  4. Write a two-sentence fix you would give a teammate.
  5. Name one related public advisory (CERT-In, CISA, NVD, or a vendor bulletin) with its date.

Indian workplace (sample data)

Suppose we are a junior analyst at Infosys, TCS, Wipro or a fintech SOC in Bengaluru/Pune. Turn this lesson into one checklist item with an owner, a due date and a place to store evidence (ticket + screenshot).

Global practice

Compare your notes with OWASP, CIS Benchmarks, NIST CSF/IR guidance or a cloud Well-Architected security question. Write five lines on what overlaps.

Everyday analogy

Explain the risk and the fix to a family member without jargon. If they can repeat the warning, you understand it well enough to teach juniors.

Key terms

  • Control: a safeguard (patch, config, process, detection).
  • Finding: a weakness backed by evidence.
  • Remediation: the fix plus how you verified it.
  • Scope: systems you have written permission to touch.
  • Least privilege: only the access the task needs.
  • Defence in depth: several layers so one failure does not end the story.

Common mistakes

  • Skipping written permission "just for a quick scan".
  • Practising on hostel, office or public targets without authorisation.
  • Collecting tool output without writing the fix.
  • Copying attack steps onto production to "verify". Defenders verify with versions, configs and patches.
  • Publishing screenshots that contain secrets, cookies or internal hostnames.

Recap

  • Evidence, fix, owner, date.
  • Own lab only.
  • Fix > spectacle.