Linux zip Command Example

Blogs ❯❯ Linux

Image could not load

Image on pixabay

what is zip ?

ZIP एक archive file format है जो lossless data compression support करता है। lossless data compression का मतलब है बिना कोई data को loss किये perfectly कम size में compress करना। ZIP file format कई compression algorithms allow / use करती है , जिनमे DEFLATE सबसे common है।

zip Command In Linux

Linux में zip एक compression और file utility package है। zip को use करने का main purpose files को compress करके file size को reduce करना है। आप एक बार में एक या एक से ज्यादा files / directories को compress करके कम size को zip file बना सकते हैं।

Linux install zip

by default , system में zip install नहीं होता है। इसे install करने के लिए नीचे दी गयी command को run करें।

$ sudo apt update
$ sudo apt install zip
Linux zip Syntax
$ zip [options] zip_filename filelist

Linux zip Command Options

बैसे तो zip command में कई options हैं जिन्हे आप zip --help command run करके देख सकते हैं।

$ zip --help

zip Command Example

Example के लिए मेरी current directory में different - different size कई files और directories हैं।

$ ls -lh
total 104K
drwxrwxr-x 2 ubuntu ubuntu 4.0K Oct 25 04:18 dir1
-rw-rw-r-- 1 ubuntu ubuntu  29K Oct 25 04:12 index.html
-rw-rw-r-- 1 ubuntu ubuntu  33K Oct 25 04:15 java.html
-rw-rw-r-- 1 ubuntu ubuntu  32K Oct 25 04:14 python.html

Note* ऊपर दिए गए example में use की गयी ls Command का use directories या directory contents को list करने के लिए किया जाता है। By default यह सभी visible files और directory को list करता है।

हम file index.html है जिसका size 29K है , इसे ही सबसे पहले zip बनाकर देखते हैं कि zip बनने के बाद इसका size क्या होता है।

$ zip index.zip index.html
adding: index.html (deflated 80%)

output में आप देख सकते हैं कि file को 80% compress किया गया है। check करने के लिए again हम ls Command run करके zip file और उसका size देख सकते हैं।

$ ls -lh *.zip
-rw-rw-r-- 1 ubuntu ubuntu 6.0K Oct 25 04:30 index.zip

तो जैसा कि आप देख सकते हैं कि index.html file को zip file में compress करने के बाद file का size 6KB ही रह गया है। और यही main reason है zip file create करने का , आप large files को small size में convert कर सकते हैं।

यह जरूरी नहीं है कि आप एक file का ही name दें , need के according एक साथ कई file name दे सकते हैं - zip my.zip file file2 file3 etc.

Add new file in existing zip

-u option का use करके किसी new file को existing zip file में add कर सकते हैं।

$ zip -u index.zip python.html
adding: python.html (deflated 75%)

Show zip content

zip के अंदर सभी content को list / देखने के लिए zipinfo command का use किया जाता है।

$ zipinfo index.zip
Archive:  index.zip
Zip file size: 14185 bytes, number of entries: 2
-rw-rw-r--  3.0 unx    29010 tx defN 22-Oct-25 04:12 index.html
-rw-rw-r--  3.0 unx    31846 tx defN 22-Oct-25 04:14 python.html
2 files, 60856 bytes uncompressed, 13865 bytes compressed:  77.2%

delete file from zip

zip से किसी file / directory को delete करने करने के लिए -d option का use किया जाता है।

$ zip -d index.zip python.html
 deleting: python.html
$ zipinfo index.zip
Archive:  index.zip
Zip file size: 6106 bytes, number of entries: 1
-rw-rw-r--  3.0 unx    29010 tx defN 22-Oct-25 04:12 index.html
1 file, 29010 bytes uncompressed, 5936 bytes compressed:  79.5%

put directory to zip

So , अभी तक तो आपने files को zip में convert किया था , किसी directory और उसके अंदर के complete content को zip में convert करने के लिए -r option का use किया जाता है।

$ zip -r index.zip dir1
 adding: dir1/ (stored 0%)
 adding: dir1/blogs.html (deflated 79%)
Understanding -r

-r का मतलब है recursively , क्योंकि आग हम -r pass नहीं करेंगे तो सिर्फ directory का name ही zip के अंदर जा पायेगा उसके अंदर कोई directory होगी उसका content compress नहीं हो पाएगा।

अगर आप , zipinfo से zip जे अंदर का content देखेंगे तो वो कुछ इस तरह से दिखेगा।

$ zipinfo  index.zip
Archive:  index.zip
Zip file size: 14377 bytes, number of entries: 3
-rw-rw-r--  3.0 unx    29010 tx defN 22-Oct-25 04:12 index.html
drwxrwxr-x  3.0 unx        0 bx stor 22-Oct-25 04:18 dir1/
-rw-rw-r--  3.0 unx    38460 tx defN 22-Oct-25 04:18 dir1/blogs.html
3 files, 67470 bytes uncompressed, 13911 bytes compressed:  79.4%

compress and move file

Well , ऊपर दिए गए सभी examples में अगर आप ध्यान दिया हो तो , file zip में compress हो जाने के बाद file move नहीं होती है , जिससे हमारा file storage बढ़ता ही है।

इसलिए file zip में directly move करने के लिए -m option का use किया जाता है।

$ zip -mu index.zip python.html
adding: python.html (deflated 75%)

I Hope, आपको Linux में zip Command के बारे में अच्छे से समझ आ गया होगा , बाकी practice के लिए आप options को combine (-mv , -mr, -mu) कर सकते हैं जैसे कि examples में दिखाया गया है।

Recent Blogs

Loading ...

Rahul Kumar

Rahul Kumar

Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)

Get connected with me. :) LinkedIn Twitter Instagram Facebook