Zipped Archives in Unix Shell
If you’re working with scripts, the time will come when you need to work with a unix archive. Generally, these are are .tar files or .tar.gz (zipped). These .tar files are commonly called “tarballs”. These are no different than any other archive/backup/zipped files, they just take a little getting used to.
How to decompress a .tar or .tar.gz archive in Windows:
Winzip is my windows-based zip file manager of choice. There are several versions available, included a free “evaluation” version. Winzip can decompress .tar and .tar.gz files locally to your hard drive. Make sure you use the wizard or select “Use Folder Names” from the Classic interface so the file structure will be maintained.
How to decompress a .tar or .tar.gz archive on your webserver:
You need shell access (telnet or ssh). If you don’t have shell access, you’ll just have to decompress the tarball local (see Windows directions above) and upload via ftp.
1) Assuming you have shell access, upload the tarball to your webserver in binary mode via ftp. (Note: Choose binary mode, not ascii or automatic detect – binary). Most of the time, you’ll want to place the tarball one level above where you want the files installed, as the structure of most tarballs begins with a folder.
2) Once the tarball is on your server, log into your shell account (ask your host for directions).
3) Use the following commands to decompress:
.tar files: tar -xvfz filename.tar
.tar.gz files: tar -xvfz filename.tar.gz
4) The files will decompress into it’s original uncompressed structure. You can browse the structure using your ftp program or other tools that are more familiar to you.
While we’re at it, let’s just round out this topic.
How to zip a folder in Unix:
To create an archive from the Unix shell (telnet/ssh), use the following command:
tar -cvzf filename.tar.gz folder-name
So, if I want to create a tarball to backup my “images” folder, I’d use the following command:
tar -cvzf images.tar.gz images
Note the space between the “z” and the name of the folder I am compressing. You can create archives of individual files as well, just replace the “folder-name” in the example with a file name (i.e. “image.jpg”).
If you need a good telnet/ssh client for windows, I recommend Putty. For more information on unix shell commands, google “unix shell commands”. There are 1,000s of good resources.