Chapter 4: Linux Advanced Commands
4.5 Archiving and compression: tar, gzip, zip
Friends, taking a backup of the website, moving logs to another server or opening a downloaded WordPress – tar is needed everywhere. Remember the flags: c create, x extract, z gzip, v verbose, f file.
मित्रांनो, वेबसाइटचा बॅकअप घ्यायचा, लॉग्स दुसऱ्या सर्व्हरवर न्यायचे किंवा डाउनलोड केलेला WordPress उघडायचा – सगळीकडे tar लागतो. Flags लक्षात ठेवा: c create, x extract, z gzip, v verbose, f file.
दोस्तों, वेबसाइट का बैकअप लेना हो, लॉग्स दूसरे सर्वर पर ले जाने हों या डाउनलोड किया हुआ WordPress खोलना हो – हर जगह tar चाहिए. Flags याद रखो: c create, x extract, z gzip, v verbose, f file.
tar -czvf site-backup.tar.gz /var/www/html # create gzip archive (c=create z=gzip v=verbose f=file)
tar -tzvf site-backup.tar.gz # list contents
mkdir -p /tmp/restore
tar -xzvf site-backup.tar.gz -C /tmp/restore # extract into a folder
tar -cJvf logs.tar.xz /var/log/nginx # xz compression (smaller, slower)
gzip big.log # -> big.log.gz gunzip big.log.gz
zip -r site.zip mysite/ # install package 'zip' if missing
unzip site.zip -d /var/www/html/ # install package 'unzip' if missing
Ravindra Bagale's Tip
Many students run tar -xzvf and unpack the archive right into the current folder, making a mess. Always first see what is inside with tar -tzvf, and give a separate folder like -C /tmp/restore. And f always goes last – if you write -czfv, v is taken as the file name.
Ravindra Bagale's Tip – मराठी
बरेच students tar -xzvf करून archive current folder मध्येच उघडतात आणि सगळा गोंधळ होतो. नेहमी आधी tar -tzvf ने आत काय आहे ते बघा, आणि -C /tmp/restore सारखा वेगळा folder द्या. आणि f नेहमी शेवटी – -czfv लिहिलं तर v ला file चं नाव समजलं जातं.
Ravindra Bagale's Tip – हिंदी
बहुत से students tar -xzvf करके archive current folder में ही खोल देते हैं और सब गड़बड़ हो जाता है. हमेशा पहले tar -tzvf से अंदर क्या है वो देखो, और -C /tmp/restore जैसा अलग folder दो. और f हमेशा आख़िर में – -czfv लिखा तो v को file का नाम समझा जाता है.
Lab
Chala, tar -czvf ~/mauli-site.tar.gz ~/labs/mauli ne backup banva, tar -tzvf ~/mauli-site.tar.gz ne list bagha, mag mkdir -p /tmp/restore karun tar -xzvf ~/mauli-site.tar.gz -C /tmp/restore ne ughda aani ls -R /tmp/restore ne check kara.
Extended teaching notes
Why this lesson matters
Cloud security is mostly IAM, network exposure, logging and secure defaults. The shared responsibility model means the provider patches the metal; you patch what you configure.
- No public databases or public admin panels.
- Roles / OIDC instead of long-lived access keys.
- CloudTrail / Activity Logs / Audit Logs on and retained.
- S3/Blob/GCS: Block Public Access; encrypt; least privilege.
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)
- Write the lesson title, date and the exact lab target you are allowed to use.
- List three owned systems (VMs, apps, or cloud accounts) where this lesson applies.
- Run one safe check from the lesson on a lab system only. Paste the command and output.
- Write a two-sentence fix you would give a teammate.
- 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.