zip and unzip in linux

So with all this migrating that I’ve been doing, I’ve come to realize that it takes an excruciatingly long time to download thousands of files and then upload them somewhere else, even if the total filesize is relatively small. Uploading a basic WordPress install can take 10 minutes, and it’s only about 3MB worth of files. That SHOULD only take you, depending on your connection, about 10-20 seconds.

The reason it takes so long is because every time each of those files is uploaded, your FTP client has to send information to the server to connect, then upload the file, then send more information to close the connection. All of the connecting/disconnecting adds a significant amount of bandwidth and time overhead.

The solution? Upload a single file. If you were to directly upload the zipped WordPress package, it would take only 10 seconds. And if you have shell access to your server and it has zip/unzip installed on it, then you can extract the contents directly on the server. Even the extraction only takes seconds.

Again, like my post about transfering website from one server to another, I can never remember the proper command to zip or unzip a directory. There are a million different things you can do with the zip command, but I have no idea what any of them do, and they just confuse me. I figure I don’t need to be too concerned about the compression type or backup tar whatever-you-call-its when I’m just uploading photos of my dogs to my blog.

So here’s the zip command:

zip -r [output filename] [directory name to compress]

NOTE: The output filename does not need to include the file extension (i.e. .zip). Also, I think it’s best to cd into the parent directory before issuing this command. The directory name could potentially be entered as a path, but I doubt it. Not worth testing. And lastly, the -r only needs to be included if compressing an entire directory (it stands for “recursive” meaning it’ll include all files and folders inside of the specified directory). You can leave it out if compressing a single file. And lastly lastly, don’t be a bonehead and include the square brackets. I just used those as a visual cue.

And as for unzippng, the command is simply:

unzip [filename]

This time, include the .zip extension.

That’s it!

date Jan 28th 2011
author Mike
category Geek
tags(none)
  View Comments