Blog
Zipping and Unzipping Directories using Secure Shell on a Remote Server
Posted on April 28, 2014 in Command Line, Linux by Matt Jennings
- 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.
- 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 unicorn.serverland.com
:
ssh 02091c240a0b24281d1c280d0b33064601241c12241a04132f0a4a220705
- 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
.
- You will now see text similar to
02091c240a0b24281d1c280d0b33064601241c12241a04132f0a4a220705's password:
. Type your FTP password and press Enter
.
- Hopefully you have now logged into your server via SSH!
- 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.
- Navigate to a directory that you want to zip using a command similar to
cd janedoewebdesign.com/backups
.
- 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/janedoewebdesign.com/backups/dirtopzip
you want to make sure you are currently in the /janedoe/janeanedoewebdesign.com/backups
directory.
- To ensure you are in the
/janedoe/janeanedoewebdesign.com/backups
directory type pwd
and press Enter
. Hopefully you will see /janedoe/janeanedoewebdesign.com/backups
text printed out.
- 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 janeanedoewebdesign.com/backups
, and press Enter
.
- To see all of the files in your current directory type
ls -a
and press Enter
.
- Getting back to the topic at hand, type
pwd
, press Enter
. and hopefully you will see text similar to /janedoe/janeanedoewebdesign.com/backups
printed out. Once again, the goal is to zip the directory located at /janedoe/janedoewebdesign.com/backups/dirtopzip
.
- Type something like
zip -r dirtozip.zip 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 dirtozip.zip
file, including files that may be hidden like .htaccess
.
- Type
ls -a
and press Enter
and you will now see the new dirtozip.zip
file included in the list of files.
- To unzip new the new
dirtozip.zip
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
.
- 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.
- Finally to unzip the
dirtozip.zip
file, type unzip dirtozip.zip
and press Enter
.
Leave a Reply