How can Cleaning Log Files 10? Print

  • 4

There are many reasons behind the creation of log files in your cPanel and WHM account, and there are plenty of reasons why you have to eliminate some of these junk.


The why


The primary reason why your system have cPanel & WHM log files is because it allows you to review errors and other activities on your system.


Over time, your storage devices will accumulate log files. The more activities you do, the greater the amount of information these storage devices on your system will contain. As a result, the built-up of these log files consume a huge portion of your precious disk space.


In order to free up your disk space and avoid lagging systems and delayed actions, you should delete some of the old log files you no longer use as well as some data from these log files.


The how


There are several ways you can determine which files you should remove as well as methods in freeing up space on your storage devices. These include the du command, the rm command, and the tail command.


The du command


The du command allows you to determine the files and directories that eat up most of storage space inside of your /var/log directory. Running the “du -h /var/log/” (without the quotation marks) command will give you an estimated data on how much disk space each file and directory you specify makes use of.


The -h represents the argument responsible for causing the command to print the data you need in an easy-to-read format.


The rm command


Use the rm command (rm -f $file) and you can have some of your disk space freed up. With this command, you can eliminate files you no longer need from the system.


The -f represents the argument responsible for forcing the file removal process. In other words, executing this command will no longer require you to confirm whether you wish to proceed with the deletion or not. However, keep in mind that while this will save you time, you should be completely certain you want to get rid of those files.


The tail command


The tail command allows you to delete files (while keeping some of the log file’s data) to regain some disk space. Execute this command and it will read and output a file’s contents, starting from the bottom, working its way up. With this command, you can save the most recent data in your log files. It even allows you to specify how many lines you want to keep and store in another location or file.


To give you an idea, a tail command can come in the form of “tail -5000 $file-1 > $file-2” (without the quotation marks). In this example, the “5000” represents the last 5000 lines from the “$file-1” and then transfers the data into “$file-2”.


Upon successful execution, you can now eliminate the old $file-1from your file system and rename the new file. You can rename a file with the use of the mv command: “mv $old-file $new-file” (again, without the quotation marks).

Was this answer helpful?

« Back

Powered by WHMCompleteSolution