Learn how to delete files and folders in cPanel using both the File Manager and command-line interface. Follow step-by-step instructions to efficiently manage your hosting account's storage space and avoid accidental data loss.

Just like a tidy home office keeps you productive, deleting unnecessary files and folders from your hosting account is essential for maintaining optimal performance and managing storage space effectively. Whether you're clearing out outdated content or removing duplicates, knowing how to navigate cPanel's File Manager and command-line interface empowers you to keep your hosting environment organized and clutter-free.

 

Why Delete Files and Folders?

Over time, your website accumulates files and folders you may no longer need. These could be old backups, temporary files generated by scripts, or unused website elements. Cleaning them up offers several benefits:

  • Frees Up Disk Space: If your hosting plan comes with a storage limit, deleting unneeded files expands your available space for essential website content.
  • Improves Website Performance: A cluttered file structure can slow down website loading times. Regular housekeeping keeps things streamlined.
  • Enhanced Security: Unused files can create security vulnerabilities. Removing them minimizes potential risks.

 

Deleting Files and Folders Using cPanel File Manager:

  1. Access cPanel File Manager:

    • Log in to your cPanel account and navigate to the "Files" section.
    • Click on the "File Manager" icon to launch the File Manager interface.
  2. Select and Delete Files/Folders:

    • Navigate to the directory containing the file or folder you wish to delete.
    • Select the file or folder by clicking on it.
    • Click the "Delete" option from the toolbar.
    • Confirm the deletion by clicking "Confirm."

When you delete files or folders, the system does not permanently delete the files. Instead, cPanel moves the files to the Trash folder.

If you want to remove this completely, either select that option during the delete operation. Or visit /home/$username and click Empty Trash to permanently delete the Trash folder's contents.

You can also use cPanel API to purge content from the .trash folder in the user's home directory:

uapi --output=jsonpretty Fileman empty_trash

 

Deleting Files and Folders Using Command-Line (Terminal)

The command line offers a powerful way to manage files and folders in Linux. This guide equips you, the user, with the knowledge to delete files and folders precisely using the rm (remove) and rmdir (remove directory) commands.

Please note that, unlike cPanel File Manager, deleting files via the command line using the "rm" command is irreversible. Exercise caution and ensure you have backups before executing commands.

Before We Begin: A Backup is Your Best Friend

Crucially important: Always create a backup of your important files and folders before making any deletions using the command line. Mistakes can happen, and a backup ensures you can restore lost data. Refer to other documentation on creating backups in your WebHostingM cPanel account.

Understanding Key Concepts

  • File: A digital container that stores information like text, images, or programs.
  • Folder (Directory): A virtual container that organizes files within a hierarchical structure. Think of it as a filing cabinet for your digital files.
  • Path: The complete address specifying the location of a file or folder within the directory structure. Imagine the path as the directions needed to find a specific file in your filing cabinet.
  • Permissions: Control access to files and folders (read, write, execute). Understanding permissions is crucial for advanced deletion scenarios, but we'll focus on basic deletion for now.

Essential Commands:

  • rm (remove): This command is your go-to tool for deleting files.
  • rmdir (remove directory): This command is used specifically to delete empty directories.

Safety First: Test Your Knowledge (Optional)**

Before diving into deletions, consider testing your understanding in a safe environment. Create a test directory and a test file within it using your preferred method (e.g., graphical file manager). Once you're comfortable navigating to the test directory using the cd (change directory) command, proceed to the deletion steps below. Remember, these test files won't affect your actual data.

Deleting a Single File

  1. Open a terminal window: This is your command line interface.
  2. Navigate to the file's location: Use the cd command followed by the path to the directory containing the file. For example, cd /home/user/documents.
  3. Delete the file: Type the following command, replacing filename.txt with the actual name of your file:

rm filename.txt

  • Press Enter.
  • The terminal might prompt you for confirmation before deleting. Type y (yes) and press Enter to confirm.

Deleting Multiple Files

There are two main approaches to deleting multiple files:

  • Delete by Wildcard: Use the * wildcard to match multiple files with similar names.

rm *.txt # This deletes all files with the .txt extension in the current directory (use with caution!)

Important Note: Be very careful when using wildcards. Double-check the path and filenames before proceeding to avoid unintended deletions.

  • Delete with Piping: Combine the ls (list) command with | (pipe) and rm to delete files based on specific criteria displayed by ls.

ls -l | grep "^-" | awk '{print $9}' | xargs rm -f # This deletes all hidden files (files starting with ".") in the current directory (use with caution!)

Explanation:

  • ls -l: Lists files with detailed information (use ls for a simpler listing).
  • grep "^-": Filters the output to show only files starting with "-" (hidden files).
  • awk '{print $9}': Extracts the filename (9th column) from each filtered line.
  • xargs rm -f: Takes the filenames as input and deletes them using rm with the -f (force) option to bypass confirmation prompts.

Remember: These methods are powerful and can lead to data loss if used incorrectly. Proceed with caution, especially when using wildcards or piping.

Deleting an Empty Folder:

  1. Navigate to the folder's location: Use the cd command as before.
  2. Delete the folder: Type the following command, replacing folder_name with the actual name of the folder:

rmdir folder_name

  • Press Enter.
  • The terminal will display an error message if the folder is not empty.

Advanced Tip: The rm -rf command can forcefully delete a folder and its contents. However, use this with extreme caution as it's a permanent deletion and cannot be undone. It's highly recommended to only use rm -rf after carefully verifying the path and

 

WebHostingM Support

Remember: If you're a WebHostingM customer and encounter any challenges or require assistance with managing your hosting account, simply submit a ticket and our friendly engineers will be happy to help you resolve any challenges you may face.

Not a WebHostingM customer yet, but curious about the power of cPanel? WebHostingM offers fantastic cPanel hosting plans – check them out at our cPanel Marketplace and unlock a world of website management possibilities!

Did this answer help? 0 People found this helpful (0 Votes)