How to locate large files in cPanel using the terminal

November 29, 2024 / cPanel & WHM

Running low on disk space can affect your website’s performance. To resolve this, it is important to identify which files or directories are consuming the most space. cPanel’s built-in terminal offers a quick and efficient way to locate and manage large files.

This guide walks you through the process systematically.

Follow the process:

  1. Log in to cPanel.
  2. Scroll to the “Advanced” section and click on “Terminal” to access the built-in CLI.
  3. Navigate to the Correct Directory:
    1. The Terminal opens in your user’s home directory by default. To ensure you are in the correct location, type:
      cd ~
    2. Press Enter to move to the home directory.
    3. To work with website files, navigate to the public_html directory by typing:
      cd ~/public_html/
  4. Locate Large Files:
    1. Use the following command to find files larger than 100MB:
      find . -type f -size +100M -exec du -h {} \; | sort -rh | head -n 10
    2. Command Breakdown:
      • find . – Searches from the current directory.
      • -type f – Limits the search to files only.
      • -size +100M – Targets files larger than 100MB (adjust as needed).
      • -exec du -h {} \; – Displays file sizes in a readable format (e.g., MB, GB).
      • sort -rh – Sorts results by size (largest first).
      • head -n 10 – Shows the top 10 largest files.
  5. Review Results:
    The Terminal displays the largest files and their sizes. Use this data to decide which files to keep, move, or delete.
  6. Identify Large Directories
    1. To find the largest directories instead of individual files, run:
      du -h --max-depth=1 | sort -rh | head -n 10
      • –max-depth=1 – Limits the search to one directory level. Adjust this value (e.g., –max-depth=2) to include subdirectories.
  7. Delete Unnecessary Files:
    If you want to delete a file, use:

    rm filename

Warning: Always double-check before deleting files to avoid accidentally removing critical data.

Using the Terminal in cPanel is a straightforward and efficient way to locate large files and manage your disk space. Regular maintenance ensures optimal performance and prevents storage-related issues.

For additional support, seek assistance from our support staff.

Spread the love