How to Delete Files and Folders in cPanel and via Command Line Make it Rain Paper

  • cPanel File Manager, cPanel File Management
  • 0

Pre-requirements

  • Access to your cPanel account or SSH for command line usage.
  • Basic understanding of file management in cPanel or Linux command line.
  • Always make sure to back up important data before deleting files or folders.

Deleting Files Using cPanel File Manager

If you've already created a new web hosting account and logged in to your cPanel account, follow these steps to delete files or folders:

  1. Scroll to the Files section and click on the File Manager icon.
  2. Navigate to the correct folder or directory where the file or folder is located.
  3. Click to select the file or folder you wish to delete.
  4. Click on the Delete option in the toolbar.
  5. Confirm the deletion by clicking Confirm in the prompt that appears.

Note:

When you delete a file in cPanel File Manager, it moves the file to the "Trash" folder. You can restore the file if needed, or you can permanently delete it by emptying the Trash.

Deleting Files Using the Command Line (SSH)

To delete files or folders using SSH, be cautious, as this action is often irreversible. Always double-check before executing the delete command.

1. Verify Your Current Directory

To ensure you're in the right location, use the pwd (print working directory) command:

pwd

This will display your current directory. You can also use:

echo $PWD

2. List Files in the Directory

To list the files in a specific directory, you can use:

cd public_html/testing && ls -al

3. Deleting a Single File

To delete a specific file, use the rm command:

rm public_html/testing/index.txt

This will delete the file index.txt from the public_html/testing directory. Once removed, the file cannot be recovered.

4. Deleting Multiple Files

If you want to delete multiple files interactively (i.e., being prompted before each deletion), use:

rm -i file1.txt file2.txt file3.txt

5. Deleting All Files of a Certain Type

To remove all files of a certain type (e.g., .php files), use a wildcard:

rm *.php

6. Deleting Hidden Files (e.g., .htaccess)

To delete hidden files (files starting with a dot), such as .htaccess in the public_html directory:

find public_html/ -type f -name ".*" -delete

Gotchas to Avoid

  • Remember, deleting files with the rm command on Linux is permanent. Once deleted, files cannot be recovered without a backup.
  • Always double-check the files you're about to delete to avoid accidentally removing critical system or website files.

Clearing and Managing Log Files

If your error_log file is taking up too much space, you can clear it without deleting the file entirely:

cat /dev/null > public_html/error_log

or

echo > public_html/error_log

Rotating Logs via Cron Job

If you want to rotate or clear logs that grow too large, you can set up a cron job to automatically delete large log files:

find /home -path /home/$username-prune -false -o -type f -size 2M -name error_log -exec rm -f '{}' \;

Deleting Folders in Linux

To delete an empty folder, you can use the rmdir command:

rmdir public_html/testing

If the folder is not empty, you will need to use the rm -r command to delete it recursively:

rm -r public_html/testing

Force Deleting a Directory

To forcibly delete a directory and its contents without being prompted for confirmation:

rm -rf public_html/testing

Whether you are deleting files or folders via cPanel or the command line, always be cautious, especially when using commands like rm in Linux, as these actions are often irreversible. Always make sure to back up your data before making any significant changes. If you're not sure about the command syntax, it's always best to double-check to avoid accidentally deleting important files.

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