Zipping and Unzipping Directories using Secure Shell on a Remote Server
Posted on April 28, 2014 in Command Line, Linux by Matt Jennings

  1. On a Mac open Terminal. On a Windows machine download Cygwin or follow the steps in my Accessing SSH Remotely through the Secure Shell Google Chrome Plugin post.
  2. Once you get into the shell, enter something like the example below with your username in place of janedone and your web server name in place of
  3. You will now see text that says something like RSA key fingerprint is... Are you sure you want to continue connecting (yes/no)?. Type yes and press Enter.
  4. You will now see text similar to's password:. Type your FTP password and press Enter.
  5. Hopefully you have now logged into your server via SSH!
  6. Type in ls -a and press Enter to see a list of all your files on your server. Hopefully you will see a list of files that looks the same as when you use an FTP client, like FileZilla.
  7. Navigate to a directory that you want to zip using a command similar to cd
  8. Make sure you are one level above the directory you want to zip! For example, if you are zipping a directory named dirtozip that is located at /janedoe/ you want to make sure you are currently in the /janedoe/ directory.
  9. To ensure you are in the /janedoe/ directory type pwd and press Enter. Hopefully you will see /janedoe/ text printed out.
  10. If needed, to navigate up a directory type cd .. and press Enter. To navigate down a directory type the directory name you are going down to, like cd, and press Enter.
  11. To see all of the files in your current directory type ls -a and press Enter.
  12. Getting back to the topic at hand, type pwd, press Enter. and hopefully you will see text similar to /janedoe/ printed out. Once again, the goal is to zip the directory located at /janedoe/
  13. Type something like zip -r dirtozip to zip the directory. The -r flag stands for recursive and ensures that all sub-directories and files inside of the the dirtozip directory are included in the new file, including files that may be hidden like .htaccess.
  14. Type ls -a and press Enter and you will now see the new file included in the list of files.
  15. To unzip new the new file, first make sure there is NOT a directory named dirtozip in the same location. Once again type ls -a and press Enter to see if there is a directory named dirtozip.
  16. If there is a dirtozip directory use FTP software like FileZilla to download it to your Desktop to back it up. To delete the dirtozip directory type rm -rv dirtozip and press Enter.
  17. Finally to unzip the file, type unzip and press Enter.

Leave a Reply

To Top ↑