RedHat Linux server में कैसे File को Compress व decompress करे

हेल्लो दोस्तों आज हम सीखते है की Redhat Linux  Server में किसी File ,Folder को किन किन Method द्वारा Compress कर उनकी Size को कम किया जा सकता है ! Linux में  Powerful compression method है जिस के द्वारा हम  File के मूल आकर से कही गुना छोटा कर सकते है !यह Compression सभी  प्रकार के Data पर लागु होता है audio ,video , text किसी भी प्रकार का Data हो उसका Extinction Change करना होता है    Linux Server में File को compress करने की कही Method है उनमे से कुछ के बारे में हम जानेगे और Particle करेंगे

compression

1. tar -cvf compression 

1. यहाँ में कुछ blank फाइल create कर रहा हु जिनको TAR  -CVF से एक Compress File में collect किया जाये गा

—यहाँ हम ने 26 फाइल बनाई है touch commands के through

 

[root@localhost exp]# touch {a..z}.txt
[root@localhost exp]# ls
a.txt  c.txt  e.txt  g.txt  i.txt  k.txt  m.txt  o.txt  q.txt  
s.txt  u.txt  w.txt  y.txt b.txt  d.txt  f.txt  h.txt  j.txt  
l.txt  n.txt  p.txt  r.txt  t.txt  v.txt  x.txt  z.txt

2. यहाँ tar -cvf commands के through सभी .Txt एक्सटेशन फाइल को एक all .tar कंप्रेस File में Collect करते है  

[root@localhost exp]# tar -cvf all.tar *txt

यह all.tar जो new file  बना है ये File की size को कम तो नही करता है पर same file का collection कर लेता है और फिर इस folder को हम Compress कर के रख सकते है ये हमारे लिए इस लिए आवश्यक होता है की अगर हमारे पास 500kb की 10 लाख या उससे भी ज्यादा Files है तो हम उनको एक एक file को Compress करना काफी मुश्किल होगा और समय की बर्बादी होगी तो इससे बहतर है की हम उनको Collect करके compress कर दे                                                                                                            (note-इस all .tar फाइल पर Bzip2 और Gzip compression method यूज़ कर सकते है इसका विवरण निचे  topic 5 में दिया गया है जिसमे Gzip और Bzip2 compress किया गया है tar file के साथ )

3. अब हम सभी .txt फाइल को remove कर देते है 

[root@localhost exp]# rm -rf *txt
[root@localhost exp]# ls -l
total 24
-rw-r--r-- 1 root root 20480 Jan 29 15:21 all.tar
[root@localhost exp]#

3. और अब हमे यह देखना हो की all .txt में कोन-कोनसी फाइल है तो हम निम्न कमांड्स से देखेंगे

[root@localhost exp]# tar -tvf all.tar
-rw-r--r-- root/root         0 2017-01-29 14:48:25 a.txt
-rw-r--r-- root/root         0 2017-01-29 14:48:25 b.txt
-rw-r--r-- root/root         0 2017-01-29 14:48:25 c.txt
-rw-r--r-- root/root         0 2017-01-29 14:48:25 d.txt
-rw-r--r-- root/root         0 2017-01-29 14:48:25 e.txt
-rw-r--r-- root/root         0 2017-01-29 14:48:25 f.txt
-rw-r--r-- root/root         0 2017-01-29 14:48:25 g.txt
-rw-r--r-- root/root         0 2017-01-29 14:48:25 h.txt
-rw-r--r-- root/root         0 2017-01-29 14:48:25 i.txt
-rw-r--r-- root/root         0 2017-01-29 14:48:25 j.txt
-rw-r--r-- root/root         0 2017-01-29 14:48:25 k.txt
-rw-r--r-- root/root         0 2017-01-29 14:48:25 l.txt
-rw-r--r-- root/root         0 2017-01-29 14:48:25 m.txt
-rw-r--r-- root/root         0 2017-01-29 14:48:25 n.txt
-rw-r--r-- root/root         0 2017-01-29 14:48:25 o.txt
-rw-r--r-- root/root         0 2017-01-29 14:48:25 p.txt
-rw-r--r-- root/root         0 2017-01-29 14:48:25 q.txt
-rw-r--r-- root/root         0 2017-01-29 14:48:25 r.txt
-rw-r--r-- root/root         0 2017-01-29 14:48:25 s.txt
-rw-r--r-- root/root         0 2017-01-29 14:48:25 t.txt
-rw-r--r-- root/root         0 2017-01-29 14:48:25 u.txt
-rw-r--r-- root/root         0 2017-01-29 14:48:25 v.txt
-rw-r--r-- root/root         0 2017-01-29 14:48:25 w.txt
-rw-r--r-- root/root         0 2017-01-29 14:48:25 x.txt
-rw-r--r-- root/root         0 2017-01-29 14:48:25 y.txt
-rw-r--r-- root/root         0 2017-01-29 14:48:25 z.txt

3 . अब हम all.tar को Decompress कर सभी फाइल को वापस access कर सकते है निम्न Commands से  

[root@localhost exp]# tar -xvf all.tar
a.txt
b.txt
c.txt
d.txt
e.txt
f.txt
g.txt
h.txt
i.txt
j.txt
k.txt
l.txt
m.txt
n.txt
o.txt
p.txt
q.txt
r.txt
s.txt
t.txt
u.txt
v.txt
w.txt
x.txt
y.txt
z.txt
[root@localhost exp]# ls
all.tar  b.txt  d.txt  f.txt  h.txt  j.txt  l.txt  n.txt  p.txt 
 r.txt  t.txt  v.txt  x.txt  z.txt   a.txt    c.txt  e.txt  g.txt 
 i.txt  k.txt  m.txt  o.txt  q.txt  s.txt  u.txt  w.txt  y.txt

2. zip Compression

 1.  इस compression में यहाँ में dd commands के through 200M की garbage फाइल बना कर compress कर रहा हु आप चाये तो इसकी जगह कोई भी फाइल ले सकते है

[root@localhost exp]# dd if=/dev/sda of=ram.txt bs=2M count=100
100+0 records in
100+0 records out
209715200 bytes (210 MB) copied, 4.08322 seconds, 51.4 MB/s
[root@localhost exp]# dd if=/dev/sda of=shyam.txt bs=2M count=100
100+0 records in
100+0 records out
209715200 bytes (210 MB) copied, 0.438385 seconds, 478 MB/s
[root@localhost exp]# ls
ram.txt  shyam.txt

2. यहाँ ZIP Compression के द्वारा ram और shyam file से demo .zip file बनाई जा रही है

[root@localhost exp]# zip demo.zip *txt
  adding: ram.txt (deflated 93%)
  adding: shyam.txt (deflated 93%)
root@localhost exp]# ls -l
total 438572
-rw-r--r-- 1 root root  29200536 Jan 29 18:17 demo.zip
-rw-r--r-- 1 root root 209715200 Jan 29 18:10 ram.txt
-rw-r--r-- 1 root root 209715200 Jan 29 18:10 shyam.txt

3. अब ram और shyam file को remove करते है और हमारे पास बचती Demo .zip file को केसे decompress किया जाता है यह हम निम्न commands से देखते है

[root@localhost exp]# rm -rf *txt
[root@localhost exp]# ls -l
total 28556
-rw-r--r-- 1 root root 29200536 Jan 29 18:17 demo.zip
[root@localhost exp]# unzip demo.zip
Archive:  demo.zip
  inflating: ram.txt
  inflating: shyam.txt               
[root@localhost exp]# unzip demo.zip

3. GZIP/GUNGIP(.gn)Compression

1 .यह Compresss बहुद ही powerful compress होता है इसके द्वारा हम किसी बड़ी फाइल को कंप्रेस कर सकते है पर इस compress में एक खामी है की हम इसमे एक एक फाइल को ही compress कर सकते है यह Compress तोडा टाइम ज्यादा लेता है यहाँ में dd commands के through एक 400MB की File बना रहा हु उसको GZIP के through Compress करेंगे

[root@localhost exp]# dd if=/dev/sda of=demo2.txt bs=2M count=200
200+0 records in
200+0 records out
419430400 bytes (400 MB) copied, 14.2919 seconds, 29.3 MB/s

2.यहाँ हम GZIP compression की Power देख सकते है इस compression ने 400MB की File को only 23MB में convert कर दिया है

[root@localhost exp]# gzip demo2.txt
[root@localhost exp]# ls -lh
total 22M
-rw-r--r-- 1 root root 22M Jan 29 19:39 demo2.txt.gz

3. File का मूल रूप पाने के लिए इसको निम्न प्रकार से Uncompressed किया जाता है

root@localhost exp]# gunzip demo2.txt.gz
[root@localhost exp]# ls -lh
total 401M
-rw-r--r-- 1 root root 400M Jan 29 19:39 demo2.txt

4. BZIP2/BUNZIP2(.bz2) compression 

1. यह Compression gzip compression से भी ज्यादा powerful होता है और यह भी एक -एक फाइल को ही compress करता है यह फाइल Compress में तोडा time ज्यादा लेता है  हम यहाँ Demo .txt File को ही use करते है Compress में और देखते है की ये Gzip compress की तुलना मेंBzip2  400Mb की File कितनी Mb की फाइल में convert करता है

[root@localhost exp]# bzip2 demo2.txt
[root@localhost exp]# ls -lh
total 16M
-rw-r--r-- 1 root root 16M Jan 29 19:39 demo2.txt.bz2

तो यहाँ हम देखते है की ये bzip2 compression 400Mb की फाइल को 16 MB की फाइल में convert कर देता है

—-File का मूल रूप पाने के लिए इसको निम्न प्रकार से Uncompressed किया जाता है

[root@localhost exp]# bunzip2 demo2.txt.bz2
[root@localhost exp]# ls -lh
total 3.0G
-rw-r--r-- 1 root root 400M Jan 29 19:39 demo2.txt

5. TAR+GZIP(tar.gz /.tgz) compression

1 यहाँ हम tar File को  gzip के through compress करते है

[root@localhost exp]# touch {a..z}.txt
[root@localhost exp]# tar cvfz all.tgz *txt
a.txt
b.txt
c.txt
d.txt
e.txt
f.txt
g.txt
h.txt
i.txt
j.txt
k.txt
l.txt
m.txt
n.txt
o.txt
p.txt
q.txt
r.txt
s.txt
t.txt
u.txt
v.txt
w.txt
x.txt
y.txt
z.txt
[root@localhost exp]# rm -rf *txt
[root@localhost exp]# ls -ih
3201957 all.tgz

—-File का मूल रूप पाने के लिए इसको निम्न प्रकार से Uncompressed किया जाता है

[root@localhost exp]# tar xvfz all.tgz
a.txt
b.txt
c.txt
d.txt
e.txt
f.txt
g.txt
h.txt
i.txt
j.txt
k.txt
l.txt
m.txt
n.txt
o.txt
p.txt
q.txt
r.txt
s.txt
t.txt
u.txt
v.txt
w.txt
x.txt
y.txt
z.txt

6. TAR+BZIP2(tar.bz2/.bz2) Compression

1 यहाँ touch commands के through 100 file बनाई गए है ls -l के through show किया गया है में पूरी 100 files यहाँ show नही कर सकता तो कुछ files ही show की गई है

[root@localhost exp]# touch ram{1..100}.txt
[root@localhost exp]# ls
ram100.txt  ram19.txt  ram28.txt  ram37.txt  ram46.txt  ram55.txt 
ram10.txt   ram1.txt   ram29.txt  ram38.txt  ram47.txt  ram56.txt 
ram65.txt  ram74.txt  ram83.txt  ram92.txt   ram11.txt   ram20.txt  
ram2.txt   ram39.txt  ram48.txt  ram57.txt   ram12.txt   ram21.txt 
ram30.txt  ram3.txt   ram49.txt  ram58.txt ram72.txt     ram81.txt 
 ram90.txt  ram9.txt

2 अब इनको Bzip2 method के through powerful compression किया गया है

[root@localhost exp]# tar cvfj all.tbz2 *txt
[root@localhost exp]# tar cvfj all.tbz2 *txt
ram100.txt
ram10.txt
ram11.txt
ram12.txt
ram13.txt
ram14.txt
ram15.txt

आप को इस पुरे प्रोसेस में कोई प्रोब्लेम्स आती हे तो कमैंट्स करे में solve करुगा दोस्तों अगर आपको मेरे द्वरा दीगयी जानकारी अछि लगी तो फॉलो करे मेरे ब्लॉग  को में निरन्तर ऐसी नॉलेज वाली पोस्ट जब बी पिब्लिश करुगा आप को मेल मिलजाएगा और इस ब्लॉग पे बहुद ही सरल तरीके से Networking ,windows Linux ,Android  से related  पोस्ट में प्रकाशित करता रहुगा

Thank you

Writer Vishnu sharma

Leave a Reply

Your email address will not be published.