01 / 06
Writing the same contents more briefly
Last lesson you found that tar does not shrink anything. This is the one that does.
~ $ gzip origin.txtThe mechanism is very plain. It finds the repeats and puts a short mark in their place.
hello hello hello hello ... (2000 times) |write "hello, 2000 times"Measured for real, 12000 bytes becomes 61 bytes. A two-hundredth.
Of course it only shrinks that much when there is a lot of repetition.
text and logs with the same words over and over -> shrinks wellphotos, video, already-compressed things -> hardly at allPhotos (JPEG) and video are already compressed, so gzip makes them slightly bigger. Bigger because the table of marks has to go in as well, or it could not be put back.
So compression is not magic. It depends on what the contents are like.