Delete Large Log Files - Operation Not Permitted

PCZero

Well-Known Member
Dec 13, 2003
647
73
178
Earth
In /usr/local/cpanel/logs theer are several very large log files.

error_log
spamd_error_log
tailwatchd_log

I want to delete these and free up a ton of disk space but when I keep getting this message when I try to rm the files...



[email protected] [/usr/local/cpanel/logs]# rm error_log
rm: remove regular file `error_log'? y
rm: cannot remove `error_log': Operation not permitted
[email protected] [/usr/local/cpanel/logs]#


How can I purge these files before they grow to consume my entire drive?
 

cPanelLauren

Forums Analyst II
Staff member
Nov 14, 2017
8,537
699
263
Houston
cPanel Access Level
DataCenter Provider
Hi @PCZero!

cPanel has the cPanel Log Rotation (cpanellogd) feature which would do this for you cPanel Log Rotation Configuration - Version 76 Documentation - cPanel Documentation

You can set the log rotation size threshold for these as well at WHM>>Server Configuration>>Tweak Settings

Using these methods would be the advisable way to automatically remove cPanel specific log data.


If you must remove the data on your own you'd need to modify the attributes of the log file as they're set to append only though I really wouldn't advise doing this

Code:
lsattr /usr/local/cpanel/logs/error_log
-----a-------e-- /usr/local/cpanel/logs/error_log
To modify the file attributes you would use chattr and do something like:

Code:
chattr -a /usr/local/cpanel/logs/error_log
Then to actually clear the log file I wouldn't use rm I would do something like the following:

Code:
cat /dev/null > error_log
Thanks!
 

PCZero

Well-Known Member
Dec 13, 2003
647
73
178
Earth
OK I go to the tweak settings and see nothing under the logs tab about limiting, deleting, or controlling the error_log file.