Monday, 26 November 2012

Centos 6/RHEL Zip a file/folder

Like the USB format commands, I sometimes forget the Zip file/folder commands so here it is to remind me.

First install Zip if not already there.

$ sudo yum -y install zip 

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * Webmin:
 * base:
 * epel:
 * extras:
 * updates:
Setting up Install Process
Package zip-3.0-1.el6.i686 already installed and latest version

The syntax to zip up a folder is

$ zip -r <> <folder_to_be_zipped>

$ zip -9 -r <> <folder_to_be_zipped>

$ zip <> <file_to_be_zipped>

$ zip -9 <> <file_to_be_zipped>

-9 is to invoke the maximum compression value, you can leave it off for the default compression.

So as an example, to zip up an xvid .avi file should the need arise.

$ zip -r factory.avi  (avi files wont compress)

  adding: factory.avi (deflated 1%)

So we have a look inside with Xarchiver, there it is.

To zip up a test folder containing various compressible files and using default and maximum compression.

$ zip -r test_folder

$ zip -9 -r test_folder

Although it often does not seem that the compression makes all that much difference, those are the usual commands.

To unzip the folder or file just

$ unzip <zip_file/folder_name>

Zip folders in Linux are usable cross platform.

$ zip -h for more options and flags.

That's it, simple zipping and unzipping.