How to compress files using cPanel or the command line

This article describes two ways to compress files:

  • Using cPanel.
  • Using the command line.

About file compression

Compressing files enables you to store files using less disk space. For example, if you have some files that you rarely use, it may be worth compressing them so they take up less space. Alternatively, if you need to transfer files to or from your hosting account, it is often easier (and faster) to compress multiple files into one compressed file and transfer that file instead.

There are many types of compressed files: ZIP, RAR, tar, gzip, and more. The following procedures demonstrate how to create some of these types of files.

Method #1: Use cPanel

To compress files using cPanel, follow these steps:

  1. Log in to cPanel.
    If you do not know how to log in to your cPanel account, please see this article.
  2. Open the File Manager:
    • If you are using the Jupiter theme, on the Tools page, in the Files section, click File Manager:

      cPanel - File Manager icon (Jupiter theme)

    • If you are using the Paper Lantern theme, in the FILES section of the cPanel home page, click File Manager:

      cPanel - File Manager icon

  3. In the left sidebar, click the folder that contains the files you want to compress.
  4. To select multiple files:

    • Hold the Shift key and click to add a group of items to the currently selected items.
    • Hold the Ctrl key and click to add one item to the currently selected items.
  5. After you have selected all of the files you want to compress, on the top menu bar, click Compress:
  6. In the Compress dialog box, under Compression Type, select the type of compression to use.

    Zip Archive files are easily decompressed in Microsoft Windows. Other compression types may require additional applications to use in Windows. For more information, please see this article.
  7. In the text box, type the name of the compressed archive file.
  8. Click Compress File(s).
  9. When compression is complete, the Compression Results dialog box appears.
  10. Click Close.

    To decompress a compressed file, right-click the file in File Manager, and then click Extract.

Method #2: Use the command line

There are many ways to compress files from the command line. The following procedure outlines a few of them:

  1. Log in to your account using SSH.
  2. At the command prompt, type one of the following commands:
    • To create a ZIP file that contains all of the files in the current directory, type the following command:
      zip new.zip *
      • To also include any subdirectories and their files, use the -r option. For example:
        zip -r new.zip *
      • To decompress the .zip file, use the unzip command. For example:

        unzip new.zip
    • To create a tar file that contains all of the files in the current directory as well as any subdirectories, type the following command:

      tar cvf new.tar *

      To decompress a .tar file, use the x option instead of the c option. For example:

      tar xvf new.tar
    • To create a compressed gzip file, type the following command. Replace test.txt with the name of the file you want to compress. This command replaces the existing file with the compressed file (for example, test.txt becomes test.txt.gz):

      gzip test.txt
      • To compress all files in the current directory and all files in any subdirectories, use the -r option. For example:
        gzip -r .
      • To decompress a .gz file, use the gunzip command. For example:

        gunzip test.txt.gz
Get Linux Hosting

Article Details

  • Operating System: Linux Hosting
  • Level: Intermediate

Did you find this article helpful? Then you'll love our support. Experience the A2 Hosting difference today and get a pre-secured, pre-optimized website. Check out our web hosting plans today.

We use cookies to personalize the website for you and to analyze the use of our website. You consent to this by clicking on "I consent" or by continuing your use of this website. Further information about cookies can be found in our Privacy Policy.