A passionate programmer’s findings in the world of internet.

Zip a Folder Using Command Line

Wednesday, June 6th, 2007

As far as I know, the built-in compressed zip folder function in Windows XP does not provide any command line tools. To zip a folder using batch script or command line, one can install command line tool provided by 7zip.

It can be done with installation of whole 7zip package or just use an executable file provided by 7zip. I prefer the latter option.

Download the "7-Zip Command Line Version" from 7zip download page and unzip it.

Use the following command to zip a folder:

7za a -tzip <archive-name> <folder-name>

e.g. 7za a -tzip test.zip "New Folder"

Although this seems to be quite useless to be run in command line, but it's extremely useful if you need to create batch script to automatically zip a folder. For my case, I need it to zip a folder and FTP it to a server. By this way, I can backup a folder to server without having to consider the recursive FTP upload problem.

Zip a Folder in Linux

Thursday, May 31st, 2007

I keep forgetting the command to zip a folder in Linux (Red Hat Enterprise Linux 4). And I have even got all files in the folder got zipped individually when I typed the command wrongly, which looked funny to me. The correct command, to remind myself:

zip -9 -r <zip file> <folder name>

To zip a single file:

zip -9 <zip file> <filename>

Use "-9" for best compression. The compressed file works fine with Windows XP compression tool.