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

5. Linux Basic Commands

Chala mitrano, aajpasun terminal ha tumcha best friend aahe. Kali Linux pan Linux aahe, aani tumhi hack karnar te servers pan bahutek Linux aahet – mhanun Linux commands yeta nasteel tar cyber security madhe ek pan paul pudhe jaata yenar nahi. Suruvatila kaala screen bhitidayak vatel, ghabru naka. Roj ardha taas type kara, ek aathavdyat mouse peksha fast vhal. Aaj aapan basic commands shikuya – navigation, files, permissions, users, packages aani processes.

What you will learn in this chapter

  • The Linux file-system hierarchy and why /etc, /var/log and /home matter
  • Navigating, creating, copying, moving and deleting files and folders
  • Viewing files and following logs live
  • Permissions (r, w, x), chmod, chown, and special permissions like SUID
  • Users, groups and sudo
  • Package management with yum (Amazon Linux) and apt (Ubuntu), processes, help and editors

Concepts in this chapter

  1. 5.1The Linux File-System Hierarchy
  2. 5.2Navigation
  3. 5.3Working with Files and Directories
  4. 5.4Viewing Files and Following Logs
  5. 5.5Permissions: r, w, x, chmod and chown
  6. 5.6Users, Groups and sudo
  7. 5.7Package Management: yum and apt
  8. 5.8Processes
  9. 5.9Getting Help and Editing Files (nano, vim)

The chapter recap is at the end of the last concept page.

Chapter 5: Linux basic commands — practice tasks

Open chapter lessons · Full guided lab: linux practice folder safe permissions (not repeated here)

5.1 Build a safe evidence folder

EasyBanking

Why: Investigators keep files in a folder only they can read.

What: Create ~/case-001 with notes.txt, readable only by you.

How:

  1. mkdir -p ~/case-001
  2. echo 'Case for HDFC-test branch, Pune' > ~/case-001/notes.txt
  3. chmod 700 ~/case-001 && chmod 600 ~/case-001/notes.txt
  4. ls -ld ~/case-001; ls -l ~/case-001

Expected output: drwx------ for the folder, -rw------- for the file.

Hint

700 = rwx for owner only.

Answer / how to check
  1. Try sudo -u nobody cat ~/case-001/notes.txt → Permission denied.

5.2 Find large and recent files

MediumIT

Why: Attackers drop big archives or new scripts. find helps you spot them.

What: List files in /tmp changed in the last day and files over 10 MB in /var.

How:

  1. find /tmp -type f -mtime -1 -ls
  2. sudo find /var -type f -size +10M -exec ls -lh {} \;
  3. Write down anything unexpected.

Expected output: Mostly logs and package caches in /var.

Hint

-mtime -1 = less than 1 day.

Answer / how to check
  1. Every file listed should have a known owner/program.

5.3 Count lines and words in a patient export

EasyHealthcare

Why: Before sending a file, check how many records it has.

What: Make the file below and count rows.

Data file: patients.csv

PatientIDNameCity
P101Meera JoshiNashik
P102John CarterSydney (A$)
P103Fatima KhanLucknow

About this file: Made-up patient list. Each row is one patient. Columns: PatientID = unique ID; Name = patient name; City = home city.

How:

  1. Save the data as patients.csv with nano.
  2. Run wc -l patients.csv.
  3. Run tail -n +2 patients.csv | wc -l to skip the header.

Expected output: 4 lines total, 3 records.

Hint

tail -n +2 starts from line 2.

Answer / how to check
  1. Records = total lines − 1.

Extended teaching notes

Why this lesson matters

Use this lesson to strengthen systems you own: understand the risk, practise safely in a lab, then write and apply the fix.

Apply the fix across stacks

Same class of bug, same idea in every language.

Java / Spring Boot

Parameterise queries, encode output, CSRF tokens, limited Actuator, dependency scanning.

ASP.NET Core

EF Core / parameterised SQL, Razor encoding, HTTPS, Data Protection.

Node.js / Express

helmet, parameterised SQL, npm audit, avoid eval and shell concat.

Python / Django / Flask / FastAPI

ORM, autoescape, pip-audit, Bandit; never shell=True with user input.

PHP / Laravel

PDO/Eloquent, Blade escaping, composer audit.

Go / Ruby

database/sql placeholders / ActiveRecord; html/template / ERB escaping; govulncheck / Brakeman.

nginx / Apache / Tomcat

Hide versions, TLS, security headers, least-open ports.

MySQL / PostgreSQL / MongoDB / Redis

Private networks, auth on, least-privilege users, no 0.0.0.0/0.

AWS / Azure / GCP

Roles not long-lived keys, private data stores, cloud audit logs on.

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.

Extra depth

Re-read the original short section at the top of the page, then this expansion. Together they should exceed a solid lesson length. If anything still feels thin, add your own lab screenshot and a paragraph in your notebook — that personal evidence is what interviews ask for.

  • Permission before tools.
  • Patch and config before exploits.
  • Logs and backups before blame.
  • Teach one junior the warning from this page.