How to Compress Files and Directories in cPanel and via Command Line Print

  • cPanel File Management, cPanel File Manager, cpanel hosting, cPanel Terminal, SSH
  • 0

Pre-requirements

  • Access to your cPanel account.
  • Familiarity with using File Manager or command line for file compression.
  • Basic understanding of archive formats such as .zip, .tar, .gz, and .bz2.

Step 1: Using cPanel File Manager to Compress Files

If you've successfully created a web hosting account and logged in to your cPanel account, you can easily compress files using the File Manager:

  1. Scroll down to the Files section in your cPanel interface and click on File Manager.
  2. Locate the folder that contains the files you want to compress.
  3. Select the files or directories you want to compress. (Use command ⌘ on macOS or CTRL on Linux & Windows to select multiple files).
  4. Visually confirm your selection.
  5. Click on Compress from the top-right corner of the toolbar.
  6. Choose your preferred archive format (.zip, .tar, .gz, or .bz2).
  7. Set a custom name for the archive, or leave the default name that cPanel suggests.
  8. Click Compress File(s) to begin the process.
  9. Once compression is complete, close the window.
  10. Highlight the newly created archive and click Download from the toolbar to save the file locally.

Gotchas to Avoid

  • Ensure that you've selected the correct files and directories before compressing, as the process cannot be undone without manually uncompressing and rechecking files.
  • Choose an appropriate archive format based on your needs (e.g., use .zip for Windows users or .tar.gz for Linux users).

Step 2: Compressing Files via Command Line (SSH)

If you're comfortable with the command line, you can compress files and directories using the following tar or zip commands.

Using tar to Compress Files

To compress a directory or multiple files using tar:

tar -czvf archive.tar.gz /path/to/directory_or_file

For example, to compress the about folder inside public_html:

tar -czvf about.tar.gz public_html/about/

If you're already inside the public_html directory, you can use:

pwd
tar -czvf about.tar.gz about/

Using tar to Remove a File from the Archive

If you need to remove a file from a tarball (compressed tar archive), use:

tar --delete -f archive.tar.gz filename

Using zip to Compress Files

To compress multiple files into a zip archive:

zip archive.zip file1.txt file2.txt file3.txt

To zip all files with a specific extension (e.g., .txt) in the current directory, use a wildcard command:

zip archive.zip *.txt

To compress an entire directory recursively, such as wp-content:

zip -r wp-content.zip wp-content/

Gotchas to Avoid

  • Make sure you have sufficient disk space before creating large archives.
  • Ensure that your file permissions remain intact after compression. Some formats like tar preserve file permissions better than zip.
  • When compressing a large number of files, monitor server performance to avoid overloading it during the compression process.

Compressing files in cPanel or via the command line is a simple yet powerful way to manage your web hosting resources. Whether you're preparing backups, migrating data, or simply optimizing your file storage, these methods will help you archive files efficiently. Choose the method and archive type that best fits your workflow.

If you want to add to this tutorial or have found an error in it, please send an email to team+editorial@webhostingm.com


Did this answer help?

« Back

Trusted by over 35,000 customers in over 200 countries