How to clean unmanaged files

How to Clean Unmanaged Log Files

 

Warning:

This document describes an unsupported workaround that is not guaranteed to work in the future.

  • After these steps are performed on a server, it is the system administrator's responsibility to manage and maintain the server's database software.
  • We recommend that only experienced system administrators attempt to perform these steps.
  • We are not responsible for any data loss that is caused by an attempt to perform these steps.

This guide provides the steps to reduce the file size of the log files on your server that you do not manage through WHM's  How to Clean Unmanaged Log Files  interface (WHM >> Home >> Service Configuration >> cPanel Log Rotation Configuration).

Check disk space usage and compress old log files

cPanel & WHM creates and maintains log files. These log files allow you to examine errors and other occurrences on the system.

After an extended period of time, the log files grow to significant sizes on the system's storage devices. cPanel & WHM archives log files with the cpanellogd daemon. However, this daemon does not archive all log files. To reduce the amount of disk space that the log files occupy, you should compress these log files.

Delete log files in cPanel


Check the disk space from the command line

Before you begin, ensure that you are logged in to the terminal as the root user.

Use the du command to see which files and directories consume the most space inside of the /var/log directory.

du -h /var/log/
  • The du command prints the estimated disk space usage of each file and directory for the path that you specified.
  • The -h argument causes the command to print the information in a human-readable format. When you issue the command in the above example, the du utility prints the estimated disk space of each file and directory that the /var/log directory path contains.

The numbers in the left column of the output represent the file size of each file and directory that the specified directory path contains, in human-readable format.

 Example

Example

The output of the du command should resemble the following example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
root@host [~]# du -h /var/log/
24K    /var/log/cups
16K    /var/log/mail
36K    /var/log/prelink
19M    /var/log/audit
84K    /var/log/bandwidth/2011/Jun
128K   /var/log/bandwidth/2011/Jan
116K   /var/log/bandwidth/2011/Feb
712K   /var/log/bandwidth/2011
4.5M   /var/log/bandwidth
2.6G   /var/log/munin
8.0K   /var/log/conman.old
8.0K   /var/log/pm
8.0K   /var/log/conman
12K    /var/log/dcpumon/boot.1308161402
5.3M   /var/log/dcpumon
8.0K   /var/log/vbox
3.7G   /var/log/

Notes:

It is possible that you may see more output from the utility than the example shows. Due to the size of the files and directories in the /var/log directory path, the du utility may require some time to produce an output.

 

 


 

Select the files or directories that you want to clear

You can clear individual files within a directory.

 Example

Example

The /var/log/munin directory uses 2.6 G of space, and is the second largest log on the list.

Use the cd command to move the prompt to the /var/log/munin/ directory. Then, use the du -h * command to see the file sizes.

The output should resemble the following example:

1
2
3
4
5
6
7
root@host [~]# cd /var/log/munin/
root@host [/var/log/munin]# du -h *
603M   munin-graph.log
385M   munin-html.log
67M    munin-limits.log
99M    munin-node.log
1.5G   munin-update.log

The du -h command, without the asterisk, shows the directory's size.

The output should resemble the following example:

1
2
root@host [/var/log/munin]# du -h
2.7 G.

 

 

 


 

Empty the files

Use the cat command (concatenate) to empty the log files or directories.

cat /dev/null > munin-update.log 
  • /dev/null is a non-existent file with no information.
  • When you concatenate /dev/null to a log file, you empty the file data, but do not delete the file name.

Example

Empty a file

The output from the previous example shows that the munin-update.log file occupies 1.5G of space in the drive.

To empty this file, use the cat command.

The output should resemble the following example:

1
2
root@host [/var/log/munin]# cat /dev/null > munin-update.log
root@host [/var/log/munin]#

To confirm that you successfully emptied the file, use the du -h * command.

The output should resemble the following example:

1
2
3
4
5
6
7
root@host [/var/log/munin]# cat /dev/null > munin-update.log
root@host [/var/log/munin]# du -h *
603M   munin-graph.log
385M   munin-html.log
67M    munin-limits.log
99M    munin-node.log
0M     munin-update.log

 

Log rotation

cPanel & WHM's log rotation system compresses and stores old log files in /usr/local/cpanel/logs/archive/ directory. These actions also help you manage and reduce the amount of disk space that your hard drive uses.

Enable and configure log rotation in WHM's  How to Clean Unmanaged Log Files  interface (WHM >> Home >> Service Configuration >> cPanel Log Rotation Configuration).

The system stores the archived log files indefinitely, so you must remove them manually. Use the rm command to remove older log files.

 

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How Do I Clear My Web Browser's Cache?

Each time you access a file through your web browser, it is cached (stored). In this way, certain...

How to Upload a File using the File Manager

You can upload your files directly through cPanel using the File Manager. File Manager is a web...

How to Find the URL of a File

If you want to share a web file with friends or the public, you first need to determine the...

Video tutorials not playing

In some cases our Video Tutorials are not playing or loading after displaying the SiveHost...

My Site is Slow

You have attempted to load your site and it appears to be running slow. Now what? We understand...