User Tools

Site Tools


developmental:how-to-compress-or-extract-files-ssh-and-cpanel

How to Compress and Uncompress Files

Difficulty
Easy
Easy

Introduction

When transferring files to or from your server, it's always best to compress them to make the transfer slightly smaller, and most importantly guard against corruption during the transfer process.

What is compression?

Any Windows, Linux and Apple computer are able to compress files. There are several different kinds of compression, but we'll focus on the three most common compression file types: .zip, .tar, and .gz. Zip is a compressed archive (for multple files, usually) while tar is used for a single archive of a file. Gzip (.gz) is the compression of a file or multiple files.

You'll find that most files that are compressed on a Linux server are using the suffix ".tar.gz", while PC's will use the ".zip" compression. Windows and Mac computers have the "zip" utility by default, just like your server. So we'll work with that file type.

How do I compress a file?

On a Windows 7 PC (single file or folder)

  1. Right Click on a file or folder.
  2. Scroll down to "Send to".
  3. Click on "Compressed (zipped) folder".
  4. Type in the name of your compressed archive and hit <Enter>.

On a Windows 7 PC (multiple files)

  1. Click on a file, then press and hold "<Ctrl>".
  2. Click on each file you want to add to your archive - you can add as many as you want.
  3. Once done, let go of <Ctrl> and Right Click on one of the folders or files you have selected.
  4. Scroll down to "Send to".
  5. Click on "Compressed (zipped) folder".
  6. Type in the name of your compressed archive and hit <Enter>.

On a Mac (single file or folder)

  1. Single Click + <Control> on a file or folder.
  2. Click on "Compress <file name here>"
  3. This will compress the file automatically, and highlight the compressed file or folder.
  4. If you want to rename the archive:
  • Single Click + <Control> on the archive.
  • Click on "Rename"
  • Type in the name you wish to rename the archive to, and hit <Return>.

On a Mac (multiple files)

  1. Click on a file, then press and hold "<Command>".
  2. Click on each file you want to add to your archive - you can add as many as you want.
  3. Once done, let go of <Command> and Single Click + <Control> on one of the folders or files you have selected.
  4. Click on "Compress <#> Items".
  5. This will compress all of the files automatically, and highlight the compressed file or folder.
  6. If you want to rename the archive:
  • Single Click + <Control> on the archive.
  • Click on "Rename"
  • Type in the name you wish to rename the archive to, and hit <Return>.

How do I uncompress the file once I transfer it?

Once you transfer the file to your server using FTP, or via the cPanel File Manager ((cPanel » Home » Files » File Manager) you can uncompress the file(s) you compressed on your computer, and they'll retain the same directory structure in the location you uncompress.

Uncompressing an archive using cPanel's File Manager

  1. Login to your cPanel account located at https://domain.tld:2083
  2. Navigate to "Home > Files > File Manager" and click on the File Manager Icon.
    A new tab with the File Manager should open on your browser.
  3. On the left side, navigate to the location you transferred your archive to, and click on it.
  4. In the center pane, the location of the folder you clicked on should open. Locate your archived file.
  5. Single click the archived file.
  6. On the top bar, just below "Search" & "Settings", is a row of commands. Locate "Extract" and press it.
  7. A popup titled "Extract" should appear. If you want to change the path of where the files will uncompress to, type in the location. Otherwise, leave the edit box in the middle un-modified.
  8. Click on "Extract File(s)".
  9. Once done, a new popup with the title "Extraction Results" should pop up, describing the uncompression.

Uncompressing an archive using SSH

  1. Connect to your server using PuTTy or terminal command line "SSH". Remember to edit the port to point to the correct one.
  2. Navigate to the location where your archive is.
  3. Use the command "unzip <name of your file>".
  4. Once done, the command will scroll and describe the uncompression.

How do I compress a file on my server?

You can compress a file on your server just like you can from your computer, though it's a little different. There are multiple ways to do this, but we'll focus on SSH and the cPanel File Manager.

Compressing file(s) and folder(s) in cPanel's File Manager

  1. Login to your cPanel account located at https://domain.tld:2083
  2. Navigate to "Home > Files > File Manager" and click on the File Manager Icon.
    A new tab with the File Manager should open on your browser.
  3. On the left side you can navigate to the folder(s) or file(s) you wish to compress.
    Keep in mind you can only compress folders and files in the same directory with the File Manager.
  4. Click on the file(s) and folder(s) you wish to compress.
    If on Windows, you can press <Ctrl> and click multiple items.
    If on Mac, you can press <Command> and click multiple items.
  5. On the top bar where "File, Folder, Copy, Move" commands are located, the command "Compress" is located at the end.
  6. Press on "Compress".
  7. Select Compression Type - you should choose "Zip" since Mac and Windows both have these utilities installed by default.
  8. Enter the name of what you want the compressed file to be, and press "Compress File(s)".
  9. A popup named "Compression Results" should appear, descriibing the compression.

Compressing file(s) and folder(s) via SSH

  1. Connect to your server using PuTTy or terminal command line "SSH". Remember to edit the port to point to the correct one.
  2. Navigate to the location where you want to compress your file(s) or folder(s).
  3. Use the command "zip" to compress the files:
    To compress multiple folders or files, you should always use the "-r" option, which stands for "recursively". This will ensure all folder contents are compressed along with the folder, and not just the folder.
  4. Once done, the command will scroll and describe the compression, and creating the archive in the process.
 Example: zip -r myfiles.zip docs/ myfileone.txt public_html/ knownhostisawesome.txt php.ini

The above command will create a zip file called "myfiles.zip" and then compress the folders "docs" and "public_html", and the files "myfileone.txt, knownhostisawesome.txt, and php.ini".

developmental/how-to-compress-or-extract-files-ssh-and-cpanel.txt · Last modified: 2018/03/20 20:22 by Daniel P.