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.

Share on FacebookTweet about this on TwitterShare on LinkedInEmail this to someone

8 thoughts on “Zipped Archives in Unix Shell”

  1. Huh? okay whatever you just said… Could you, Would you send me the directions to get yours and Merrin's comments to keep my info? ::smile::

    Pretty Please…. I do click the remember info box… ::smile:: Really I do.

  2. I think it must have something to do with your browser – in some way. To remember you, it has to send a cookie and the browser eats it (munch, munch, yum!) so that -when you come back- (POOF!) we remember you!

    I think it has to be a cookie problem, because it is working for so many others. Can you receive a cookie in your browser or is it turned off? You might check the settings. Other than that, I'm stumped!

  3. Huh…. oh ya the cookie thing… others blogs remember me only yours and Merrin's do not… thought it was punishment for smarta$$es. But this one does now…. Oh boy … now I won't foget what "smart" comment I have while I type in the info…. hehehe

  4. This is sooooo well written – would you mind being a "guest author" at ScriptyGoddess and letting me share it there? I would give you full credit all over the place. Or if you prefer, I can just link to it and direct people your way. Let me know what you think! 🙂

  5. Oh! Oh! Oh! I wanna be a goddess for a day! Oh! Guest author!

    Look out Merrin & your puny NYT. I'm headed for "goddess" status!

  6. I'll save you one character of typing while you're using the Unix shell. You don't need the "z" for a regular .tar file. The "z" means "run this file through the gzip program before you untar it". So for foo.tar, you would only need to type "tar -xvf foo.tar". The "z" keeps you from having to type "gunzip foo.tar.gz; tar -xvf foo.tar". BTW, an implementation of ZIP exists for linux, if that's what your websever is running on. Type "zip -h" to see if it's installed.

  7. Pingback:

Comments are closed.