Learn about cPanel file manager

The Ultimate Guide To cPanel File Manager

How to delete a file(s) or folder(s) using cPanel File Manager

This may come in handy if your hosting account files are taking up too much space.

Log in to cPanel

Scroll and find the Files section and then click on the File Manager icon.

Ensure that you are in the right folder or directory.

Click to select the file or folder you want to delete.

Select Delete from the toolbar.

To confirm that you really want to delete the file or folder, click the Confirm button.


To delete a file using the command-line utility, use the “rm” command.

A word of caution.

Deleting a file in Linux is an irrevocable act.

Let’s change directory and visually list to confirm files/folders in this location:

cd public_html/testing && ls -al

Output:

total 12
drwxr-xr-x  2 username username   24 Nov  2 04:29 .
drwxr-x--- 12 username nobody  4096 Nov  1 02:50 ..
-rw-r--r--  1 username username 6984 Oct 27 21:26 index.html

We can also just list from wherever we are:

ll public_html/testing
-rw-r--r-- 1 username username 6984 Oct 27 21:26 index.html
-rw-rw-r-- 1 username username    0 Nov  1 02:20 index.txt

Let’s now remove the “index.txt” file:

rm public_html/testing/index.txt

As you can see, if we run “ls” on our .trash folder, the file is gone and cannot be recovered:

ls -al .trash
total 4
drwx------  2 username username   28 Nov  1 22:11 .
drwx--x--x 27 username username 4096 Aug 26 06:13 ..
-rw-r--r--  1 username username    0 Nov  1 22:11 .trash_restore

Unlike doing this via cPanel File Manager, it is extremely difficult or impossible to recover deleted data on Unix-like operating systems.

When managing your files via cPanel’s File Manager, you can delete a file and send it to the “Trash”.

You also have the option to restore the file in case this was performed accidentally.

When running the “rm” command in a Linux system, you should be super careful, especially with regular expressions.

If you are not careful enough, the action will result in the deletion of important data/system files and non-intended files.

Backup.

Backup.

Backup before deleting a file in Linux via the command line.

To delete a single file:

rm $filename

If you want to interactively delete multiple files at once, simply list all of the file names after the “rm” command:

rm -i $filename1 $filename2 $filename3 $filename4 $filename5 etc

To remove a certain type of file:

rm *.php

To delete all hidden files (.htaccess, etc) in public_html:

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

But what if you don’t really want to delete these files?

You can simply archive and compress them, download the archived file and then remove these from your system.

What if the system is unable to write to your error.log because it is full?

Just run:

cat /dev/null > public_html/error_log

or

echo > public_html/error_log

You can also rotate or clear error_log files that grow to a certain size by creating a cron job:

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

If it is a WordPress website, you can elect to disable error logging by adding to “wp-config.php”:

ini_set('display_errors', 'Off');
ini_set('error_reporting', E_ALL );
define('WP_DEBUG', false);
define('WP_DEBUG_DISPLAY', false);

Deleting all files and subfolders in a folder is kinda different.

To remove a folder:

rm -d public_html/testing

or

rmdir public_html/testing

If the folder or directory is not empty, you will likely meet with an error.

This is a built-in safeguard that helps prevent the accidental loss of data.

Since there is no -r option for “rmdir”, you can recursively delete a directory by first deleting all of its contents, beginning with those in the lowest levels of sub-directories.

So to remove a directory with its contents, the most efficient method is to use the recursive option with the “rm” command:

rm -r public_html/testing

This of course will prompt you for confirmation.

To forcibly do this without prompting for confirmation or showing error messages:

cd public_html && rm -rf testing

Pages: 1 2 3 4 5 6 7 8 9 10 11 12


Posted

in

,

by