Hack 45. Advanced compression using zip command.

by Ramesh

There are 10 levels of compression provided by zip command.

  • Level 0 is the lowest level, where it just archives the file without any compression.
  • Level 1 will perform little compression. But, will be very fast.
  • Level 6 is the default level of compression.
  • Level 9 is the maximum compression. This will be slower when compared to default level. In my opinion, unless you are compressing a huge file, you should always use level 9.

In the example below, I used Level 0, default Level 6, and Level 9 compression on a same directory. See the compressed file size yourself.

  1. # zip var-log-files-default.zip /var/log/*
  2.  
  3. # zip -0 var-log-files-0.zip /var/log/*
  4.  
  5. # zip -9 var-log-files-9.zip /var/log/*
  6.  
  7. # ls -ltr
  8. -rw-r--r-- 1 root root 2817248 Jan 1 13:05 var-log-files-default.zip
  9. -rw-r--r-- 1 root root 41415301 Jan 1 13:05 var-log-files-0.zip
  10. -rw-r--r-- 1 root root 2582610 Jan 1 13:06 var-log-files-9.zip