Ravindra BagaleCourses & study guides English

Linux tar, gzip, zip आणि xz: Files archive आणि compress करा उदाहरणांसह

Backups, log shipping, code releases आणि file transfers ला दोन गोष्टी लागतात: अनेक files एका file मधे (archive) आणि ती लहान (compress). tar पहिलं करतो. gzip, bzip2, xz आणि zstd दुसरं. zip दोन्ही करतो आणि Windows वर उघडतो. प्रत्येक command आणि key option एक-एक करून, प्रत्येक step साठी safe सवयीसह शिकू.

या chapter मध्ये तुम्ही काय शिकाल

  • tar archives create, list आणि extract
  • -z, -j, -J आणि zstd ने compress
  • -C, --exclude आणि --strip-components वापरा
  • gzip, gunzip, zcat आणि -k वापरा
  • xz, bzip2 आणि zstd वापरून योग्य निवडा
  • zip आणि unzip वापरा, आणि archives verify

1. रोजचं उदाहरण: घर बदलताना packing

हे का लागतं?

कुटुंब पुण्याहून बंगळुरूला जातं तेव्हा अनेक छोट्या वस्तू एका carton मधे भरून tape लावतात. मग कपडे vacuum bags मधे दाबतात म्हणजे carton मधे जास्त मावतं. वर list चिकटवतात म्हणजे न उघडता आत काय ते कळतं.

हे काय आहे?

Carton = tar archive. Vacuum bag = compression (gzip, xz). वरची list = tar -t. नव्या घरात योग्य खोलीत unpack = tar -x -C /target.

कसं करायचं (step by step)

tar.gz कसं बनतं आणि उघडतंtar folder फिरून प्रत्येक file नाव, owner, mode आणि time सह लिहितोStream gzip (-z) मधून जातो, तो लहान करतोResult: एक .tar.gz fileउघडताना gzip stream मोठा करतोtar प्रत्येक entry वाचून target folder खाली files बनवतोRoot म्हणून extract केलं तरच owners restore
दुसऱ्याचं archive extract करण्याआधी नेहमी list (-t) करा.

2. tar -c: archive बनवा

हे का लागतं?

हजारो ऐवजी copy, upload किंवा backup साठी एक file हवी.

हे काय आहे?

tar -c create. -f NAME archive file नाव (नावाच्या लगेच आधी). -v जाताना files list. Add करायचे folders किंवा files द्या. Relative paths म्हणजे cleanly extract.

कसं करायचं (step by step)

  1. Folder pack.
tar -cvf site.tar www/

Output:

www/
www/index.html
www/css/app.css

याचा अर्थ: एक file, अजून compressed नाही.

  1. Parent folder मधून.
cd /var && sudo tar -cf /tmp/www.tar www && ls -lh /tmp/www.tar

Output:

-rw-r--r--. 1 root root 51M Oct 25 13:30 /tmp/www.tar

याचा अर्थ: Paths www/ पासून.

3. tar -t: extract न करता list

हे का लागतं?

आत काय आहे ते तपासायचं, आणि unpack आधी विचित्र paths वर लिहिणार नाही याची खात्री.

हे काय आहे?

tar -tf FILE entries list. Sizes, owners, dates साठी -v. Compressed files ना पण (वाचताना tar compression ओळखतो).

कसं करायचं (step by step)

  1. List.
tar -tf site.tar | head -3

Output:

www/
www/index.html
www/css/app.css

याचा अर्थ: Safe, relative paths.

  1. Long list.
tar -tvf site.tar | head -2

Output:

drwxr-xr-x ravi/ravi    0 2026-10-25 13:20 www/
-rw-r--r-- ravi/ravi 2140 2026-10-25 13:20 www/index.html

याचा अर्थ: ls -l सारखं.

4. tar -x आणि -C: extract, आणि कुठे ते निवडा

हे का लागतं?

चुकीच्या folder मधे extract केल्याने files home मधे मिसळू शकतात किंवा overwrite.

हे काय आहे?

tar -xf FILE सध्याच्या folder मधे. -C DIR DIR मधे (तो असायला हवा). Archive नंतर path दिला तर फक्त ती file किंवा folder. -k (--keep-old-files) overwrite नाकारतो.

कसं करायचं (step by step)

  1. नव्या folder मधे extract.
mkdir -p /tmp/restore && tar -xf site.tar -C /tmp/restore && ls /tmp/restore

Output:

www

याचा अर्थ: Contained आणि नीट.

  1. फक्त एक file.
tar -xf site.tar -C /tmp/restore www/index.html

Output:

(no output)

याचा अर्थ: एका page चा पटकन restore.

  1. Overwrite नको.
tar -xkf site.tar -C /tmp/restore

Output:

tar: www/index.html: Cannot open: File exists

याचा अर्थ: तुमची नवी copy ठेवतो.

5. tar -z: gzip compression (.tar.gz, .tgz)

हे का लागतं?

Logs आणि text 5 ते 10 पट compress. gzip fast आणि सगळीकडे उघडतो.

हे काय आहे?

-z जोडा .tar.gz create किंवा extract साठी. ओळखीचे short forms: tar -czf (create), tar -tzf (list), tar -xzf (extract). Modern tar extract ला compression ओळखतो, म्हणून -xf पण चालतो.

कसं करायचं (step by step)

  1. tar.gz बनवा.
tar -czf logs-2026-10-25.tar.gz /var/log/shop/ 2>/dev/null; ls -lh logs-2026-10-25.tar.gz

Output:

-rw-r--r--. 1 ravi ravi 6.2M Oct 25 13:35 logs-2026-10-25.tar.gz

याचा अर्थ: 48 MB वरून 6.2 MB.

  1. Extract.
tar -xzf logs-2026-10-25.tar.gz -C /tmp/restore

Output:

(no output)

याचा अर्थ: बनवताना सुरुवातीचा / काढला.

6. tar -J आणि -j: xz आणि bzip2

हे का लागतं?

खूप वेळ ठेवायच्या किंवा अनेकदा download होणाऱ्या files साठी speed पेक्षा लहान size महत्त्वाची.

हे काय आहे?

-J xz (.tar.xz): सर्वात लहान, सर्वात slow. -j bzip2 (.tar.bz2): जुना, मधला. XZ_OPT=-9 ने level किंवा सगळ्या CPU cores साठी -I 'xz -T0'.

कसं करायचं (step by step)

  1. xz archive.
tar -cJf release.tar.xz build/ && ls -lh release.tar.xz

Output:

-rw-r--r--. 1 ravi ravi 3.9M Oct 25 13:40 release.tar.xz

याचा अर्थ: gzip च्या 6.2M पेक्षा लहान.

  1. सगळे cores.
tar -I 'xz -T0' -cf release.tar.xz build/

Output:

(no output)

याचा अर्थ: मोठ्या servers वर खूप fast.

  1. bzip2.
tar -cjf old.tar.bz2 build/

Output:

(no output)

याचा अर्थ: कोणी .bz2 मागितलं तरच.

7. tar सह zstd: fast आणि लहान

हे का लागतं?

Backups आणि CI caches साठी gzip जवळची speed आणि xz जवळची size हवी. zstd दोन्ही देतो.

हे काय आहे?

tar --zstd -cf FILE.tar.zst (GNU tar 1.31+). Level आणि threads साठी -I 'zstd -T0 -19'. एकच file decompress साठी zstd -d FILE.zst.

कसं करायचं (step by step)

  1. tar.zst बनवा.
tar --zstd -cf cache.tar.zst node_modules/ && ls -lh cache.tar.zst

Output:

-rw-r--r--. 1 ravi ravi 41M Oct 25 13:45 cache.tar.zst

याचा अर्थ: पटकन बनतं आणि उघडतं.

  1. Extract.
tar --zstd -xf cache.tar.zst

Output:

(no output)

याचा अर्थ: नेहमीचाच -x.

8. --exclude आणि --exclude-from

हे का लागतं?

Backup किंवा release मधे node_modules, .git, caches किंवा secrets नको.

हे काय आहे?

--exclude=PATTERN जुळणारे skip (folder नावांच्या आधी द्या). परत द्या, किंवा -X FILE (--exclude-from) ने file मधे patterns. --exclude-vcs .git वगैरे skip.

कसं करायचं (step by step)

  1. Junk शिवाय release.
tar --exclude=node_modules --exclude='*.log' --exclude-vcs -czf app.tgz app/

Output:

(no output)

याचा अर्थ: लहान आणि स्वच्छ.

  1. File मधून.
printf '.env\n*.pem\ntmp/\n' > .tarignore && tar -X .tarignore -czf app.tgz app/

Output:

(no output)

याचा अर्थ: Secrets बाहेर जात नाहीत.

  1. काही leak नाही ना.
tar -tzf app.tgz | grep -E '\.env|\.pem' || echo none

Output:

none

याचा अर्थ: नेहमी तपासा.

9. --strip-components, -p आणि --same-owner

हे का लागतं?

Downloaded releases मधे app-1.2.3/ सारखा top folder असतो जो नको. Backups ला permissions हव्या.

हे काय आहे?

--strip-components=1 extract ला पहिला path भाग काढतो. -p permissions ठेवतो (root ला default). --same-owner owners restore (root ला default). Systems मधे हलवताना --numeric-owner नावं नाही, IDs.

कसं करायचं (step by step)

  1. Version folder काढा.
tar -xzf node-v22.10.0-linux-x64.tar.gz -C /opt/node --strip-components=1 && ls /opt/node

Output:

bin  include  lib  share

याचा अर्थ: bin थेट /opt/node मधे.

  1. Owners सह backup.
sudo tar -cpzf etc-backup.tgz --numeric-owner /etc

Output:

tar: Removing leading `/' from member names

याचा अर्थ: Warning normal.

10. gzip आणि gunzip: एक file

हे का लागतं?

जुने logs आणि SQL dumps single files; फक्त लहान करायच्या.

हे काय आहे?

gzip FILE FILE ला FILE.gz ने replace. -k original ठेवतो. -d किंवा gunzip decompress. -1 fastest, -9 smallest (default 6). -l ratio. -r folder मधली प्रत्येक file. gzip files वर, folders वर नाही (folders साठी tar).

कसं करायचं (step by step)

  1. Compress करा, original ठेवा.
gzip -k -9 dump.sql && ls -lh dump.sql*

Output:

-rw-r--r--. 1 ravi ravi 210M Oct 25 13:50 dump.sql
-rw-r--r--. 1 ravi ravi  31M Oct 25 13:50 dump.sql.gz

याचा अर्थ: दोन्ही ठेवल्या.

  1. Ratio.
gzip -l dump.sql.gz

Output:

  compressed        uncompressed  ratio uncompressed_name
    32505111           220200960  85.2% dump.sql

याचा अर्थ: 85% बचत.

  1. Decompress.
gunzip -k dump.sql.gz

Output:

gzip: dump.sql already exists; do you wish to overwrite (y or n)?

याचा अर्थ: -k आणि आधीची file: विचारतो.

11. zcat, zless आणि zgrep: unpack न करता वाचा

हे का लागतं?

Rotated logs .gz असतात. सगळे unpack करणं disk आणि वेळ वाया.

हे काय आहे?

zcat FILE.gz text print. zless pages. zgrep PATTERN FILE.gz search. xzcat, bzcat, zstdcat इतर formats साठी तेच.

कसं करायचं (step by step)

  1. जुने logs शोधा.
sudo zgrep -c ' 500 ' /var/log/nginx/access.log.2.gz

Output:

37

याचा अर्थ: त्या दिवशी 37 server errors.

  1. पहिल्या lines.
zcat dump.sql.gz | head -n 2

Output:

-- PostgreSQL database dump
-- Dumped from database version 16.4

याचा अर्थ: File लिहिली नाही.

12. Single files वर xz, bzip2 आणि zstd

हे का लागतं?

प्रत्येक tool चा pattern सारखा, gzip माहीत असलं की सगळे माहीत.

हे काय आहे?

xz FILE / unxz FILE.xz / xz -k -T0 -9. bzip2 FILE / bunzip2. zstd FILE (default original ठेवतो) / zstd -d / unzstd. सगळे -k आणि -d support. -c stdout ला.

ToolSpeedSizeकशासाठी
gzipFastमध्यमLogs, web, सगळीकडे
bzip2Slowलहानजुन्या systems
xzसर्वात slowसर्वात लहानReleases, archives
zstdखूप fastलहानBackups, CI, streaming

कसं करायचं (step by step)

  1. सगळ्या cores सह xz.
xz -k -T0 dump.sql && ls -lh dump.sql.xz

Output:

-rw-r--r--. 1 ravi ravi 22M Oct 25 13:55 dump.sql.xz

याचा अर्थ: 22M vs gzip 31M.

  1. zstd.
zstd -T0 dump.sql

Output:

dump.sql : 13.10%   (210 MiB => 27.5 MiB, dump.sql.zst)

याचा अर्थ: Fast, original ठेवली.

  1. Dump थेट compressed file मधे.
pg_dump shopdb | zstd -T0 > shopdb.sql.zst

Output:

(no output)

याचा अर्थ: मोठी temp file नाही.

13. zip आणि unzip

हे का लागतं?

Windows आणि Mac users, emails आणि अनेक web uploads .zip मागतात.

हे काय आहे?

zip -r OUT.zip FOLDER folder जोडतो. -q quiet. -x 'pattern' exclude. -e password विचारतो (कमकुवत, अवलंबू नका). unzip FILE.zip extract; -d DIR folder मधे; -l list; -o न विचारता overwrite; -q quiet.

कसं करायचं (step by step)

  1. Report folder zip.
zip -rq reports-oct.zip reports/ -x '*.tmp' && ls -lh reports-oct.zip

Output:

-rw-r--r--. 1 ravi ravi 2.4M Oct 25 14:00 reports-oct.zip

याचा अर्थ: Email साठी तयार.

  1. List.
unzip -l reports-oct.zip | tail -n 3

Output:

     8120  2026-10-25 13:58   reports/gst.csv
---------                     -------
  9921040                     14 files

याचा अर्थ: आत 14 files.

  1. Folder मधे extract.
unzip -q reports-oct.zip -d /tmp/rep && ls /tmp/rep

Output:

reports

याचा अर्थ: Contained.

zip सविस्तर: -r, -e, -u आणि -9

हे का लागतं?

Windows आणि Mac वाले .zip double click ने उघडतात. Client, CA किंवा teacher ला files पाठवायच्या असतील तर zip हा सगळ्यात safe format.

हे काय आहे?

zip अनेक files एका .zip मधे भरतो आणि त्याच वेळी compress करतो. आधी zip चं नाव, मग add करायच्या files किंवा folders.

नेहमीचे options

Optionकाय करतो
-rRecursive: folder आणि आतलं सगळं add.
-eEncrypt: password विचारतो आणि zip lock करतो.
-uUpdate: existing zip मधे फक्त नव्या किंवा बदललेल्या files.
-9सर्वोत्तम (हळू) compression. -1 सर्वात fast. Default 6.
-qQuiet: प्रत्येक file चं नाव print नाही.
-xPattern जुळणाऱ्या files वगळा.

कसं करायचं (step by step)

  1. -r ने आख्खा folder zip.
zip -r gst-2026.zip gst-2026

Output:

  adding: gst-2026/ (stored 0%)
  adding: gst-2026/april.csv (deflated 71%)

याचा अर्थ: -r नसेल तर फक्त रिकाम्या folder ची entry मिळते.

  1. -e ने password लावा.
zip -er salary-slips.zip slips

Output:

Enter password:
Verify password:
  adding: slips/ (stored 0%)

याचा अर्थ: Password शिवाय zip उघडत नाही. Type करताना password दिसत नाही.

  1. -u ने बदललेली file add.
zip -u gst-2026.zip gst-2026/may.csv

Output:

updating: gst-2026/may.csv (deflated 70%)

याचा अर्थ: फक्त नवी किंवा नवीन file आत जाते. बाकी तशाच राहतात.

  1. -9 ने जास्त compress.
zip -9 -r photos-best.zip photos && ls -lh photos-best.zip

Output:

-rw-r--r-- 1 asha asha 41M Oct 25 10:12 photos-best.zip

याचा अर्थ: -9 थोडा लहान पण हळू. Photos आधीच compressed असतात, म्हणून फायदा कमी.

खालच्या tasks मधे सराव करा: सराव tasks

unzip सविस्तर: -l, -d, -o, -t आणि एक file

हे का लागतं?

लोक email आणि links ने zips पाठवतात. उघडण्याआधी आत बघणं, योग्य folder मधे उघडणं आणि file खराब नाही ना ते तपासणं गरजेचं.

हे काय आहे?

unzip .zip उघडतो. Option नसेल तर सगळं current folder मधे extract. Zip नंतर file नावं दिली तर फक्त त्याच extract.

नेहमीचे options

Optionकाय करतो
-lआतल्या files list, extract नाही.
-d DIRDIR folder मधे extract (गरज असेल तर बनतो).
-oExisting files न विचारता overwrite.
-nExisting files कधीच overwrite नाही.
-tZip खराब आहे का test, extract नाही.
-qQuiet output.
zip file1Zip मधून फक्त file1 extract.

कसं करायचं (step by step)

  1. आधी -l ने आत बघा.
unzip -l vendor-kyc.zip

Output:

  Length      Date    Time    Name
---------  ---------- -----   ----
   182044  2026-10-20 09:14   pan.pdf
    90211  2026-10-20 09:15   aadhaar.pdf
---------                     -------
   272255                     2 files

याचा अर्थ: आत दोन PDFs आहेत. Disk वर काहीच लिहिलं नाही.

  1. -d ने ठरलेल्या folder मधे.
unzip vendor-kyc.zip -d /srv/kyc/v102

Output:

Archive:  vendor-kyc.zip
  inflating: /srv/kyc/v102/pan.pdf
  inflating: /srv/kyc/v102/aadhaar.pdf

याचा अर्थ: Files current folder ऐवजी /srv/kyc/v102 मधे.

  1. -o ने जुन्या copies बदला.
unzip -o plugin-v2.zip -d wp-content/plugins

Output:

  inflating: wp-content/plugins/seo/seo.php

याचा अर्थ: "replace? [y]es, [n]o" प्रश्न नाही. Scripts साठी चांगलं.

  1. -t ने खराबी test.
unzip -t backup-sept.zip

Output:

testing: db.sql   OK
No errors detected in compressed data of backup-sept.zip.

याचा अर्थ: Zip वापरायला safe. खराब zip "bad CRC" किंवा "End-of-central-directory signature not found" दाखवतो.

  1. फक्त एक file काढा.
unzip vendor-kyc.zip pan.pdf

Output:

  inflating: pan.pdf

याचा अर्थ: फक्त pan.pdf extract. Pattern साठी quotes, उदा. "*.pdf".

खालच्या tasks मधे सराव करा: सराव tasks

14. Archives verify: -t, -d, --test आणि checksums

हे का लागतं?

Restore न होणारा backup हा backup नाही. Test केलं नाही तर corrupt archives गरजेच्या वेळीच सापडतात.

हे काय आहे?

gzip -t FILE.gz test. xz -t, zstd -t, unzip -t तेच. tar -tzf FILE > /dev/null पूर्ण वाचतो. tar -d (--compare) disk शी तुलना. sha256sum FILE > FILE.sha256, मग copy नंतर sha256sum -c.

कसं करायचं (step by step)

  1. gzip test.
gzip -t logs-2026-10-25.tar.gz && echo OK

Output:

OK

याचा अर्थ: gzip कडून output नाही = चांगलं.

  1. Zip test.
unzip -tq reports-oct.zip

Output:

No errors detected in compressed data of reports-oct.zip.

याचा अर्थ: पाठवायला safe.

  1. Upload नंतर checksum.
sha256sum app.tgz > app.tgz.sha256 && sha256sum -c app.tgz.sha256

Output:

app.tgz: OK

याचा अर्थ: दोन्ही बाजूंना सारखे bytes.

15. अनेक industries मधली खरी उदाहरणं

हे का लागतं?

तेच Linux skill प्रत्येक प्रकारच्या company मध्ये लागतं. वेगवेगळ्या ठिकाणी पाहिलं की लक्षात राहतं.

हे काय आहे?

प्रत्येक row म्हणजे एक काल्पनिक team. कोण हे वापरतं आणि कसं ते दाखवते.

कसं करायचं (step by step)

Team आणि शहरते कसं वापरतातCommand
Amit, CA office, PuneClients साठी monthly GST reports zipzip -r gst-oct.zip gst/
Hannah, SaaS, BerlinReleases .tar.xz म्हणूनtar -cJf app.tar.xz build/
Omar, bank, RiyadhNightly DB dump zstd ला streampg_dump db | zstd > db.zst
Yuki, gaming, Tokyoजुन्या rotated logs मधे zgrepzgrep 'match_id=91' access.log.3.gz
Diego, media, LimaOwners सह /etc backuptar -cpzf etc.tgz /etc
Kavya, hospital, Nashikप्रत्येक backup archive verifygzip -t backup.tgz

16. नेहमीच्या errors आणि त्यांचे fixes

हे का लागतं?

हे errors सगळ्यांना येतात. कारण माहीत असलं की तास वाचतात.

हे काय आहे?

आधी नेमका message वाचा. मग खालच्या row शी जुळवा.

कसं करायचं (step by step)

दिसणारा errorका होतंFix कसा करायचा
tar: Cowardly refusing to create an empty archive-f NAME नंतर files दिल्या नाहीतPack करायचा folder द्या.
tar -czf out.tgz folder/
tar: Removing leading `/' from member namesAbsolute path दिला; tar safe करतोNormal; किंवा relative path सह -C /.
tar -czf etc.tgz -C / etc
gzip: stdin: not in gzip formatFile gzip नाही (plain tar किंवा xz)file ने तपासा, योग्य flag.
file archive.tgz
tar: Error is not recoverable: exiting nowArchive अपूर्ण किंवा corruptपरत download; checksum verify.
sha256sum -c app.tgz.sha256
tar: f: Cannot open: No such file or directoryOption order: -fcz मधे c file नावf नावाच्या लगेच आधी.
tar -czf out.tgz dir/
tar: /target: Cannot open: No such file or directory (with -C)Target folder नाहीआधी बनवा.
mkdir -p /target
gzip: dump.sql.gz already exists; do you wish to overwrite (y or n)?Output आधीच आहेकाढा किंवा -f.
gzip -f dump.sql
zip warning: name not matched: reportsPath चुकीचा किंवा या folder मधे नाहीPath तपासा.
ls -d reports
unzip: cannot find zipfile directoryzip नाही, किंवा अपूर्ण downloadfile आणि size ने तपासा.
file reports.zip
No space left on device during tarत्याच भरलेल्या disk वर archiveदुसऱ्या disk वर किंवा stream करून बाहेर.
tar -czf - dir | ssh backup 'cat > dir.tgz'

17. Troubleshooting step by step

हे का लागतं?

Archive उघडत नसेल तर खरा type शोधा, test करा, मग रिकाम्या folder मधे extract.

हे काय आहे?

वरून खाली जा. ज्या step ला problem दिसतो तिथे थांबा.

कसं करायचं (step by step)

  1. खरं काय आहे?
file backup.tgz
  1. Size ठीक?
ls -lh backup.tgz
  1. Compression layer test.
gzip -t backup.tgz
  1. tar layer list.
tar -tzf backup.tgz | head
  1. Source शी checksum.
sha256sum backup.tgz
  1. रिकाम्या folder मधे extract.
mkdir -p /tmp/x && tar -xzf backup.tgz -C /tmp/x

18. Lab 1: Project backup आणि restore

हे का लागतं?

Project बनवा, junk शिवाय backup, verify, delete करून restore.

हे काय आहे?

पूर्ण hands-on lab. प्रत्येक step test Linux machine वर करा (EC2 instance, VM किंवा WSL).

कसं करायचं (step by step)

  1. Files बनवा.
mkdir -p proj/src proj/node_modules && echo app > proj/src/app.js && echo secret > proj/.env && echo dep > proj/node_modules/x.js

Output:

(no output)
  1. Excludes सह backup.
tar --exclude=node_modules --exclude=.env -czf proj.tgz proj/

Output:

(no output)
  1. Contents तपासा.
tar -tzf proj.tgz

Output:

proj/
proj/src/
proj/src/app.js
  1. Verify आणि checksum.
gzip -t proj.tgz && sha256sum proj.tgz > proj.tgz.sha256 && sha256sum -c proj.tgz.sha256

Output:

proj.tgz: OK
  1. Delete आणि restore.
rm -rf proj && tar -xzf proj.tgz && cat proj/src/app.js

Output:

app

19. Lab 2: gzip, xz, zstd आणि zip तुलना

हे का लागतं?

एकच file प्रत्येक tool ने compress, size आणि time तुलना, आणि एक unpack न करता वाचा.

हे काय आहे?

पूर्ण hands-on lab. प्रत्येक step test Linux machine वर करा (EC2 instance, VM किंवा WSL).

कसं करायचं (step by step)

  1. मोठी text file.
seq 1 3000000 > nums.txt && ls -lh nums.txt

Output:

-rw-r--r--. 1 ravi ravi 21M Oct 25 14:10 nums.txt
  1. gzip आणि xz.
time gzip -k nums.txt; time xz -k -T0 nums.txt

Output:

real 0m0.9s
real 0m2.8s
  1. zstd आणि zip.
zstd -q nums.txt; zip -q nums.zip nums.txt

Output:

(no output)
  1. तुलना.
ls -lh nums.txt.* nums.zip | awk '{print $5, $9}'

Output:

6.3M nums.txt.gz
1.5M nums.txt.xz
2.9M nums.txt.zst
6.3M nums.zip
  1. Unpack न करता वाचा.
zcat nums.txt.gz | tail -n1

Output:

3000000

Ravindra Bagale's Tip

Remember tar as c-x-t: Create, eXtract, lisT, and keep f last because the name follows it. Before trusting any backup, test it (gzip -t) and restore it once into an empty folder.

20. नेहमी विचारले जाणारे प्रश्न

प्र. Archive vs compress?

Archive = अनेक files एकात (tar). Compress = लहान (gzip). .tar.gz दोन्ही.

प्र. .tgz vs .tar.gz?

एकच.

प्र. कोणता format?

Compatibility साठी gzip, speed साठी zstd, सर्वात लहान साठी xz, Windows users साठी zip.

प्र. tar permissions ठेवतो?

हो, store करतो; owners restore ला root लागतो.

प्र. gzip folder compress करतो?

नाही, आधी tar, किंवा gzip -r प्रत्येक file वेगळी.

प्र. माझी .gz लहान का नाही?

आधीच compressed data (jpg, mp4, zip) लहान होत नाही.

प्र. zip -e safe?

जुनं zip encryption कमकुवत. Secrets साठी gpg किंवा 7z AES.

प्र. Temp files शिवाय folder दुसऱ्या server ला?

tar -czf - dir | ssh host 'tar -xzf - -C /dest'.

21. मुलाखत प्रश्न आणि उत्तरं

Beginner level

प्र. app folder चं .tar.gz?

tar -czf app.tgz app/.

प्र. Extract न करता tar.gz list?

tar -tzf app.tgz.

प्र. /opt मधे extract?

tar -xzf app.tgz -C /opt.

प्र. gzip ने original ठेवायची?

gzip -k FILE.

Mid level level

प्र. tar मधून node_modules exclude?

Folder आधी --exclude=node_modules.

प्र. Extract ला top folder काढायचा?

--strip-components=1.

प्र. .gz log मधे search?

zgrep PATTERN FILE.gz.

प्र. gzip vs xz vs zstd?

Speed vs size: gzip balanced, xz सर्वात लहान, zstd चांगल्या size सह fastest.

Senior level

प्र. विश्वासाचा backup design.

Consistent snapshot किंवा dump, zstd compress, checksum, offsite copy, नियमित test restore, monitor.

प्र. Tar bomb म्हणजे काय आणि कसं टाळायचं?

Top folder नसलेलं किंवा ../ paths असलेलं archive; आधी list करून रिकाम्या folder मधे extract.

प्र. 2 TB servers मधे पटकन?

tar | zstd -T0 | ssh किंवा mbuffer, किंवा resumable साठी rsync.

प्र. System backups साठी --numeric-owner का?

Restore host वर user नावं वेगळ्या IDs ला असू शकतात.

घरी करून बघा

  1. Home मधले Documents tar आणि zstd ने backup, *.iso exclude. Test करा आणि /tmp/check मधे restore.
  2. एक log file घ्या, gzip, xz आणि zstd ने compress करा, आणि size आणि time चा table लिहा.

सराव Tasks

या scenario बद्दल

Milan Furniture हा मिलान मधला फर्निचर व्यवसाय आहे. Giulia Rossi त्यांचं IT व cloud काम पाहतात. त्यांचे पैसे EUR मध्ये मोजले जातात आणि AWS resources eu-south-1 Region मध्ये चालतात. खालच्या tasks मध्ये तुम्ही या lesson मध्ये शिकलेलं वापरून त्यांची खरी कामं करता. सगळी नावं, account IDs, IP addresses व numbers सरावासाठी काल्पनिक आहेत.

0 / 22

सोपं tar.gz बनवा

का: Backups आणि transfers ला archives.

काय करायचं: site folder मधून site.tar.gz.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

सोपं Archive list

का: Backups आणि transfers ला archives.

काय करायचं: site.tar.gz मधलं list.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

सोपं Extract

का: Backups आणि transfers ला archives.

काय करायचं: site.tar.gz इथे extract.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

सोपं सर्वोत्तम gzip compression

का: Backups आणि transfers ला archives.

काय करायचं: error.log gzip ने maximum level 9.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

सोपं Uncompress

का: Backups आणि transfers ला archives.

काय करायचं: access.log.gz uncompress.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

सोपं zip बनवा

का: Backups आणि transfers ला archives.

काय करायचं: report folder report.zip मधे.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

सोपं zip list

का: Backups आणि transfers ला archives.

काय करायचं: Extract न करता report.zip list.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

सोपं xz uncompress

का: Backups आणि transfers ला archives.

काय करायचं: dump.sql.xz uncompress.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

सोपं Max zip compression

का: Backups आणि transfers ला archives.

काय करायचं: logs folder logs.zip मधे best compression level ने.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

सोपं zip check

का: Backups आणि transfers ला archives.

काय करायचं: invoices.zip extract न करता खराबी check.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

मध्यम दुसरीकडे extract

का: Backups आणि transfers ला archives.

काय करायचं: site.tar.gz /srv/www मधे.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

मध्यम xz archive

का: Backups आणि transfers ला archives.

काय करायचं: logs folder मधून logs.tar.xz.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

मध्यम Original ठेवा

का: Backups आणि transfers ला archives.

काय करायचं: access.log gzip पण original ठेवा.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

मध्यम Extract न करता वाचा

का: Backups आणि transfers ला archives.

काय करायचं: Extract न करता app.log.gz मधे ERROR.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

मध्यम दुसरीकडे unzip

का: Backups आणि transfers ला archives.

काय करायचं: report.zip /tmp/r मधे.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

मध्यम File xz

का: Backups आणि transfers ला archives.

काय करायचं: सगळ्या CPU cores ने dump.sql xz.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

मध्यम Password zip

का: Backups आणि transfers ला archives.

काय करायचं: payroll folder payroll.zip मधे password lock सह.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

मध्यम zip update

का: Backups आणि transfers ला archives.

काय करायचं: Existing site.zip मधे फक्त बदललेली index.html.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

मध्यम न विचारता unzip

का: Backups आणि transfers ला archives.

काय करायचं: theme.zip इथे extract, existing files न विचारता replace.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

मध्यम zip मधून एक file

का: Backups आणि transfers ला archives.

काय करायचं: photos.zip मधून फक्त cover.jpg.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

अवघड Files exclude

का: Backups आणि transfers ला archives.

काय करायचं: app चं app.tar.gz पण node_modules skip.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

अवघड Integrity test

का: Backups आणि transfers ला archives.

काय करायचं: backup.tar.gz खराब आहे का test.

कसं करायचं:
  1. हे काम करणारा Linux command शोधा.
  2. Task ला लागणारे options (उदा. -r, -h) जोडा.
  3. File नावं, folders किंवा users योग्य क्रमाने लिहा.
  4. System files/users बदलत असाल तर sudo वापरा. Check answer दाबा.

थोडक्यात सांगायचं तर

  1. tar -c create, -t list, -x extract, नावाआधी f.
  2. -z gzip, -J xz, -j bzip2, --zstd zstd.
  3. -C, --exclude, --strip-components result ठरवतात.
  4. Single files साठी gzip/gunzip -k, zcat आणि zgrep.
  5. Windows-friendly archives साठी zip -r आणि unzip -d.
  6. -t आणि checksums ने test; खात्रीसाठी एकदा restore.

उजळणी, तुलना आणि मुलाखत cards

हा lesson काही मिनिटांत revise करा. Cards phone वर save करा किंवा PNG download करा. प्रत्येक card वरचा QR हा lesson उघडतो.

tar c t x. Folder एका file मधे. c create, t list, x extract. z gzip, J xz, f file. Backup बनवा.
उजळणी card: tar c t x · PNG download करा · Card page उघडा
gzip zip xz. छोट्या files, जलद copies. gzip जलद, xz सगळ्यात छोटं. Windows साठी zip. Extract न करता वाचा.
उजळणी card: gzip zip xz · PNG download करा · Card page उघडा
gzip vs xz. जलद. / हळू.
तुलना: gzip vs xz · PNG download करा · Card page उघडा
tar.gz vs zip. Linux backups. / Windows शी share.
तुलना: tar.gz vs zip · PNG download करा · Card page उघडा
gzip vs xz?. gzip: जलद, common. xz: छोटं, हळू. सगळ्या cores ने xz.
मुलाखत card: gzip vs xz? · PNG download करा · Card page उघडा
tar.gz vs zip?. tar Linux permissions ठेवतो. zip सगळीकडे उघडतं. Folder zip.
मुलाखत card: tar.gz vs zip? · PNG download करा · Card page उघडा
tar मधे folders skip?. node_modules प्रचंड. --exclude वापरा. Skip करा.
मुलाखत card: tar मधे folders skip? · PNG download करा · Card page उघडा
Backup तपासा?. खराब archives restore fail. List किंवा test. gzip test.
मुलाखत card: Backup तपासा? · PNG download करा · Card page उघडा

अजून cards: Ravi Sir's Cards.